php - 在 WooCommerce 电子邮件通知中显示特定产品属性
问题描述
我无法将产品属性添加到 WooCommerce 新订单电子邮件。我已将下面的代码段添加到 email-order-items.php(在 // SKU.. 部分之后),但没有任何反应。甚至标题“位置:”也不可见。对此有什么想法吗?
// Attribute
if ( $item_meta->meta ) {echo '<br/><small>Location: ' . nl2br( $product->get_attribute( 'location' ) ) . '</small>';}
解决方案
更新- 不要覆盖 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
钩子。
推荐阅读
- graphql - 如何验证或检测 graph-ql java 中的附加请求参数?
- android - “R”或“资源”在 Android Studio 中给我错误
- python - 如何通过点击而不是语音触发 Alexa 意图?
- json - json 文件在网页上的“< >”内不显示字符串(例如“abc
") - spring - 无法解析原型
- android - Flutter 永久隐藏导航栏
- php - 如何将数据库中的数据显示到 sb-admin 模板?
- angular - 在springboot java项目中捆绑angular ui项目并访问其UI
- assembly - 程序集 8086 中数组的未知大小
- javascript - 如何从对象中的特定参数中找到我的对象中的唯一对象