我刚刚安装了这个插件WooCommerce UPC, EAN, and ISBN并激活它,以便在我的单一产品页面上有GTIN字段.
一切正常,我有显示的值在里面的字段(例如:产品代码:123456,显示在产品页面上).
我想要的是当有人下订单时,当我在Outlook上收到订单确认邮箱时,会有一个邮箱模板显示产品标题、价格、数量、BUT not showing the GTIN product code.
如何提取/显示GTIN to WooCommerce邮箱模板.
我刚刚安装了这个插件WooCommerce UPC, EAN, and ISBN并激活它,以便在我的单一产品页面上有GTIN字段.
一切正常,我有显示的值在里面的字段(例如:产品代码:123456,显示在产品页面上).
我想要的是当有人下订单时,当我在Outlook上收到订单确认邮箱时,会有一个邮箱模板显示产品标题、价格、数量、BUT not showing the GTIN product code.
如何提取/显示GTIN to WooCommerce邮箱模板.
以下是从产品中获取GTIN代码的方法,并在提交订单时将其保存为自定义订单项目,以便在订单和邮箱通知中显示:
// Utility function to get the GTIN code from the product object
function get_product_gtin_code( $product ) {
return $product->get_meta('hwp_product_gtin');
}
// Utility function to get the GTIN label name
function get_gtin_label() {
$label = get_option('hwp_gtin_text');
return esc_html__( $label ? $label : 'GTIN');
}
// Save Product GTIN as custom order item and display it on orders (items) and emails
add_action( 'woocommerce_checkout_create_order_line_item', 'save_and_display_gtin_everywhere', 10, 4 );
function save_and_display_gtin_everywhere( $item, $item_key, $values, $order ) {
if ( $gtin_code = get_product_gtin_code($values['data']) ) {
$item->add_meta_data( 'gtin_code', $gtin_code );
}
}
// Add readable "meta key" label name replacement
add_filter('woocommerce_order_item_display_meta_key', 'filter_wc_order_item_display_meta_key', 10, 3 );
function filter_wc_order_item_display_meta_key( $display_key, $meta, $item ) {
if( $item->get_type() === 'line_item' && $meta->key === 'gtin_code' ) {
$display_key = get_gtin_label();
}
return $display_key;
}
// Utility function to get the GTIN code from the order item object
function get_order_item_gtin_code( $item ) {
return $item->get_meta('gtin_code');
}
代码位于您的子主题的unctions.php文件中(或在插件中).应该能行得通.