【发布时间】:2017-03-29 13:29:44
【问题描述】:
我的页面需要在管理员的 woocommerce 电子邮件中显示不同的产品名称(新客户订单电子邮件)。要更改名称,我使用过滤器 woocommerce_order_item_name。 但我必须验证它是管理员电子邮件还是客户电子邮件。我在这段代码中使用了一个 gloab 变量,它可以工作,但我猜这不是正确的方式。那么有没有更好的解决方案来验证它是管理员电子邮件还是客户电子邮件?
woocommerce/emails/email-order-items.php
global $is_admin_email;
if($show_sku) {
$is_admin_email = True;
}
else {
$is_admin_email = False;
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
//Set to false again
$is_admin_email = False;
functions.php
function filter_woocommerce_order_item_name( $item_name, $item, $false ) {
global $is_admin_email;
if( $is_admin_email ){
$item_name = "Item name in admin email";
}
return $item_name;
};
// add the filter
add_filter( 'woocommerce_order_item_name', 'filter_woocommerce_order_item_name', 10, 3 );
【问题讨论】:
标签: php wordpress woocommerce