如何在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 );

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

尝试下面的代码。这可能会有所帮助。将此代码添加到函数.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"]');
}

相关内容

  • 没有找到相关文章

最新更新