在 WooCommerce 电子邮件通知中显示特定的产品属性

我无法向 WooCommerce 新订单电子邮件添加产品属性。我已将下面的代码段添加到 email-order-items.php(在 // SKU .. 部分之后),但没有任何反应。甚至标题“位置:”也不可见。对此有何想法?


// Attribute

if ( $item_meta->meta ) {echo '<br/><small>Location: ' . nl2br( $product->get_attribute( 'location' ) ) . '</small>';}


江户川乱折腾
浏览 127回答 1
1回答

侃侃尔雅

更新- 而不是覆盖 Woocommerce 模板,总是首先尝试使用可用的钩子,例如:add_action( 'woocommerce_order_item_meta_start', 'add_download_links_to_thank_you_page', 10, 3 );function add_download_links_to_thank_you_page( $item_id, $item, $order ) {&nbsp; &nbsp; // Set below your product attribute taxonomy (always starts with "pa_")&nbsp; &nbsp; $taxonomy = 'pa_location';&nbsp; &nbsp; // On email notifications&nbsp; &nbsp; if ( ! is_wc_endpoint_url() && $item->is_type('line_item') ) {&nbsp; &nbsp; &nbsp; &nbsp; $product&nbsp; &nbsp; = $item->get_product();&nbsp; &nbsp; &nbsp; &nbsp; $label_name = get_taxonomy( $taxonomy )->labels->singular_name;&nbsp; &nbsp; &nbsp; &nbsp; if ( $term_names = $product->get_attribute( $taxonomy ) ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<br/><small>' . $label_name . ': ' . nl2br( $term_names ) . '</small>';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。您也可以使用woocommerce_order_item_meta_end钩子代替。
打开App,查看更多内容
随时随地看视频慕课网APP