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

Php 在电子商务电子邮件通知中显示特定的产品属性,php,wordpress,woocommerce,custom-taxonomy,email-notifications,Php,Wordpress,Woocommerce,Custom Taxonomy,Email Notifications,我无法将产品属性添加到新订单电子邮件中。我已经将下面的代码片段添加到email-order-items.php(在//SKU..part之后),但是什么也没有发生。甚至滴度“位置:”也不可见。有什么想法吗 // Attribute if ( $item_meta->meta ) {echo '<br/><small>Location: ' . nl2br( $product->get_attribute( 'location' ) ) . '</smal

我无法将产品属性添加到新订单电子邮件中。我已经将下面的代码片段添加到email-order-items.php(在//SKU..part之后),但是什么也没有发生。甚至滴度“位置:”也不可见。有什么想法吗

// Attribute
if ( $item_meta->meta ) {echo '<br/><small>Location: ' . nl2br( $product->get_attribute( 'location' ) ) . '</small>';}
//属性
如果($item_meta->meta){echo'
位置:'.nl2br($product->get_属性('Location'))。'}
已更新-不要覆盖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 ) {
    // Set below your product attribute taxonomy (always starts with "pa_")
    $taxonomy = 'pa_location';

    // On email notifications
    if ( ! is_wc_endpoint_url() && $item->is_type('line_item') ) {
        $product    = $item->get_product();
        $label_name = get_taxonomy( $taxonomy )->labels->singular_name;

        if ( $term_names = $product->get_attribute( $taxonomy ) ) {
            echo '<br/><small>' . $label_name . ': ' . nl2br( $term_names ) . '</small>';
        }
    }
}
add_action('woocommerce_order_item_meta_start'、'add_download_links_to_thank_you_page',10,3);
函数添加\下载\链接\至\谢谢\页面($item\ id,$item,$order){
//在您的产品属性分类法下面设置(始终以“pa”开头)
$taxonomy='pa_location';
//关于电子邮件通知
如果(!is_wc_endpoint_url()&&$item->is_type('line_item')){
$product=$item->get_product();
$label\u name=get\u taxonomy($taxonomy)->labels->singular\u name;
if($term\u names=$product->get\u属性($taxonomy)){
回显“
”。$label_name.”:“.nl2br($term_name)。”; } } }
代码进入活动子主题(或活动主题)的functions.php文件。测试和工作

您也可以使用
woocmerce\u order\u item\u meta\u end
hook代替