【问题标题】:Display specific product attribute in WooCommerce email notifications在 WooCommerce 电子邮件通知中显示特定产品属性
【发布时间】:2019-10-07 23:04:59
【问题描述】:

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

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

【问题讨论】:

    标签: php wordpress woocommerce custom-taxonomy email-notifications


    【解决方案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 ) {
        // 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>';
            }
        }
    }
    

    代码在您的活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    您也可以使用woocommerce_order_item_meta_end 挂钩。

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 2020-12-07
      • 2021-03-26
      • 1970-01-01
      • 2019-08-27
      • 2020-09-01
      相关资源
      最近更新 更多