隐藏 Woocommerce 电子邮件中产品名称的跨度

问题描述 投票:0回答:1

我正在使用 Bright Plugins 的 Woocommerce 预购,并且我想在所有客户电子邮件中隐藏“预购日期”(红色)。

我尝试将这行代码添加到我的子主题的functions.php 文件中,但它没有过滤掉该行。我使用了正确的元键,但它似乎是一个跨度。 代码如下:

add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'unset_specific_order_item_meta_data', 10, 2);
function unset_specific_order_item_meta_data($formatted_meta, $item){
    // Only on emails notifications
    foreach( $formatted_meta as $key => $meta ){
        if( in_array( $meta->key, array('_preorder_date') ) )
            unset($formatted_meta[$key]);
    }
    return $formatted_meta;
}
php wordpress woocommerce
1个回答
0
投票

您使用的密钥似乎可能存在小拼写错误。数组中的键“预订日期”应与您尝试删除的元键完全匹配。

更换

PreOrder Date

_pre_order_date

这是代码。

add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'unset_specific_order_item_meta_data', 10, 2);
function unset_specific_order_item_meta_data($formatted_meta, $item){
    // Only on emails notifications
    foreach( $formatted_meta as $key => $meta ){
        if( in_array( $meta->key, array('_pre_order_date') ) ) // Corrected key name
            unset($formatted_meta[$key]);
    }
    return $formatted_meta;
}
© www.soinside.com 2019 - 2024. All rights reserved.