在woocommerce电子邮件中输出产品自定义字段(图像)

马尔科 I。

我的 WooCommerce 商店中的产品通过高级自定义字段插件添加了一个自定义字段store_email_logo这个字段是一个图像字段,我不知道如何在 WooCommerce 电子邮件中输出图像。

我尝试了下面的代码,但它不起作用,它输出一些数字而不是图像。

// Tested on WooCommerce version 2.6.x and 3+ — For simple products only.
add_action('woocommerce_email_after_order_table', 'wcv_ingredients_email_logo', 10, 4);
function wcv_ingredients_email_logo( $order,  $sent_to_admin,  $plain_text,  $email ){
    foreach($order->get_items() as $item_values){
        // Get the product ID for simple products (not variable ones)
        $product_id = $item_values['product_id'];
        $output = get_post_meta( $product_id, 'store_email_logo', true );
        echo ' ' . $output . '<br>';
    }
}
炸薯条

显示的“数字”是与您的产品相关联的图像的 ID。有几个函数可以为您输出实际图像。我非常偏爱这个wp_get_attachment_image_src($image_id, $size)功能。

add_action('woocommerce_email_after_order_table', 'wcv_ingredients_email_logo', 10, 4);
function wcv_ingredients_email_logo( $order,  $sent_to_admin,  $plain_text,  $email ){
    foreach($order->get_items() as $item_values){
        // Get the product ID for simple products (not variable ones)
        $product_id     = $item_values['product_id']; //get the product ID
        $image_id       = get_post_meta( $product_id, 'store_email_logo', true ); //get the image ID associated to the product
        $image_src      = wp_get_attachment_image_src( $image_id, 'full' )[0]; //get the src of the image - you can use 'full', 'large', 'medium', or 'thumbnail' here,
        $image          = '<img src="'.$image_src.'">'; //create the img element
        echo $image . '<br>'; //echo the image
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 woocommerce 电子邮件标题中输出产品自定义字段

在订单电子邮件通知中输出产品自定义字段值

在Woocommerce管理员电子邮件通知中显示产品自定义字段值

在Woocommerce订单和电子邮件中显示产品变体的自定义字段

在WooCommerce“订单已完成”电子邮件中添加自定义产品字段

在woocommerce订单电子邮件中显示多个产品的自定义字段

在WooCommerce电子邮件订购项目中显示可变产品的产品自定义字段

产品标签的WooCommerce自定义电子邮件

WooCommerce-每个产品的自定义电子邮件

将产品自定义字段添加到WooCommerce已完成的订单电子邮件中

如何在新订单电子邮件中显示WooCommerce自定义产品元?

在Woocommerce中销售产品时向卖家发送自定义电子邮件

在WooCommerce订单和电子邮件通知中显示自定义字段值

在Woocommerce管理员,订单和电子邮件中显示自定义付款字段

在Woocommerce中启用自定义结帐电子邮件字段验证

在WooCommerce电子邮件通知中为管理员显示自定义字段

WooCommerce电子邮件模板中的ACF自定义字段

WooCommerce电子邮件上的订单自定义字段中的替换收件人

基于WooCommerce中的自定义字段值的电子邮件收件人

订单自定义字段未显示在WooCommerce电子邮件通知中

WooCommerce 订单电子邮件中未显示自定义电话号码字段

WooCommerce 电子邮件模板中的高级自定义字段

获取要在 Woocommerce 电子邮件通知中显示的自定义字段值

使用Woocommerce电子邮件中的自定义字段自定义格式化的计费全名

Woocommerce新订单电子邮件通知中的自定义“回复”电子邮件标题

根据 WooCommerce 电子邮件通知中的产品类别添加自定义文本“每个项目”

在Woocommerce中的特定电子邮件通知上为特定产品添加自定义文本

在WooCommerce的电子邮件和订单页面中保存并显示产品自定义数据

在WooCommerce电子邮件通知上显示自定义产品图片