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

用户名

我想在Woocommerce的“订单完成”电子邮件中添加唯一的文本,但是仅当购买的产品具有特定的产品标签时才可以。如果购买的商品带有“筹款人”标签,我希望电子邮件中包含文字,感谢他们支持我们的筹款人。长话短说,但我们不能为此使用类别,而必须使用标签。

我试过编辑customer-complete-order.php文件,此方法有效,但是我对PHP代码不满意,并且没有如何调用标记的示例。

我还尝试根据其他人的操作来编辑functions.php,据我所知。

function woocommerce_custom_email_per_product_depending_on_product_tag( $email_heading, $order ) {
global $woocommerce;
$items = $order->get_items();
foreach ( $items as $item ) {
    $product_tag = $item['product_tag'];
    if ( $product_tag == fundraiser ) {
        $email_body = 'Thanks for buying a fundraiser.';
    }
    return $email_heading;
}   }

还是最好在新的电子邮件模板中定义此自定义文本?这是woocommerce提供的订单确认模板。

<?php
/**
 * Customer completed order email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates/Emails
 * @version 3.5.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<p><?php esc_html_e( 'We have finished processing your order.', 'woocommerce' ); ?></p>
<?php

/*
 * @hooked WC_Emails::order_details() Shows the order details table.
 * @hooked WC_Structured_Data::generate_order_data() Generates structured data.
 * @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
 * @since 2.5.0
 */
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );

/*
 * @hooked WC_Emails::order_meta() Shows order meta data.
 */
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );

/*
 * @hooked WC_Emails::customer_details() Shows customer details
 * @hooked WC_Emails::email_address() Shows email address
 */
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );

?>
<p>
<?php esc_html_e( 'Thanks for shopping with us.', 'woocommerce' ); ?>
</p>
<?php

/*
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

7uc1f3r
function woocommerce_custom_email_per_product_depending_on_product_tag( $order, $sent_to_admin, $plain_text, $email ) {
    $items = $order->get_items();

    foreach ( $items as $item ) {               
        // get an array of the WP_Term objects for a defined product ID
        $terms = wp_get_post_terms( $item['product_id'], 'product_tag' );

        foreach($terms as $term){
            $term_names[] = $term->name; // Product tag Name

            //$term->term_id; Product tag Id
            //$term->slug; Product tag slug
        }
    }

    if ( $email->id == 'customer_processing_order' && in_array('Fundraiser', $term_names) ) {
        echo 'Thanks for buying a fundraiser.';
    }
}
add_action( 'woocommerce_email_before_order_table', 'woocommerce_custom_email_per_product_depending_on_product_tag', 10, 4 );

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

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

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

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

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

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

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

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

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

根据产品属性添加自定义woocommerce电子邮件

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

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

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

在Woocommerce电子邮件下载中用自定义元替换产品名称

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

自定义电子邮件丢失的产品和小计

Woocommerce的自定义电子邮件(Wordpress)

Woocommerce自定义电子邮件结帐

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

Woocommerce-自定义电子邮件类创建重复的电子邮件

为特定的Woocommerce电子邮件通知向BCC添加自定义电子邮件

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

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

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

获取Woocommerce自定义电子邮件内容的自定义电子邮件占位符值

通过添加自定义表来自定义WooCommerce电子邮件

WooCommerce:使用自定义电子邮件通知添加自定义订单状态

解码前端和后端(和电子邮件)上的产品自定义

PrestaShop 1.6 将订单产品添加到自定义电子邮件模板

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