如何在Woocommerce客户邮件中添加“相关产品”

时间:2019-04-16 09:32:09

标签: php wordpress email woocommerce hook-woocommerce

我想在Woocommerce客户邮件中显示4种相关产品,但是当我只是在customer-processing-order.php内调用简码时,没有任何反应。

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

/**
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php echo do_shortcode('[related_products limit="4"]'); ?>

<p><?php _e( "Your order has been received and is now being processed. Your order     details are shown below for your reference:", '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 );

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

我知道需要一个钩子或可以调用的东西来显示这些相关产品,但到目前为止,我所尝试的所有方法都无法正常工作或使整个系统崩溃。

1 个答案:

答案 0 :(得分:0)

尝试以下代码。这可能会有所帮助。将此代码添加到functions.php文件中

add_action( 'woocommerce_email_after_order_table', 'custom_related_product', 10, 2 );
function custom_related_product( $order, $is_admin_email ) {
    echo do_shortcode('[related_products limit="4"]');
}