WooCommerce隐藏客户电子邮件中的订单商品元

时间:2017-08-25 18:01:23

标签: php wordpress woocommerce

我有一个针对自定义元数据的Woocommerce插件。我有四个,但其中两个不应该显示在客户的电子邮件中(但在我的后端)。所以我尝试编辑email-order-items.php并删除标准wc_display_item_meta($ item); 在我的代码的第一部分,我尝试删除其中的两个,在第二部分,我尝试显示其他两个

$_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);

        $item_meta = wc_gzdp_get_order_meta($_product, $item);
        $item_meta_print = '';

        if ($item_meta->meta) {

            if (is_array($item_meta->meta)) {
                foreach ($item_meta->meta as $key => $value) {
                    if (stripos($key, "_wccf_pf_donotshow") === 0 || 
                    stripos($key, "_wccf_pf_donotshow2") === 0) {
                        unset($item_meta->meta[$key]);
                    }
                }
            }
            $item_meta_print = $item_meta->display(true, true, '_', ", ");

            if(isset($item_meta->meta['_wccf_pf_show'])) {
                $item_meta_print .= ', Name: '. $item_meta->meta[_'wccf_pf_show'];
            } elseif(isset($item_meta->meta['_wccf_pf_show2'])) {
                $item_meta_print .= ', Name2: '. $item_meta->meta['_wccf_pf_show2'];
            }

        }

这适用于之前的Woocommerce版本,但不再适用于Woocommerce 3.客户电子邮件中不再有任何形式: - (

如果有任何帮助,我将非常感激。

2 个答案:

答案 0 :(得分:1)

通过过滤woocommerce_order_item_get_formatted_meta_data的结果,这将在前端的任何地方隐藏键:

/**
 * Hide container meta in emails.
 *
 * @param  array  $meta
 * @return array
 */
function kia_hide_mnm_meta_in_emails( $meta ) {
    if( ! is_admin() ) {
        $criteria = array(  'key' => 'Part of' );
        $meta = wp_list_filter( $meta, $criteria, 'NOT' );
    }
    return $meta;
}
add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'kia_hide_mnm_meta_in_emails' );

我认为没有条件仅在电子邮件中进行此过滤。

答案 1 :(得分:0)

我找到了解决方案。也许它可以帮助别人

              if ( $item != '_wccf_pf_donotshow' || $item != '_wccf_pf_donotshow2') {
            $order->display_item_meta( $item );

        }

                $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);

        $item_meta = wc_gzdp_get_order_meta($_product, $item);


        if ($item_meta->meta) {

            if(isset($item_meta->meta['_wccf_pf_show'])) {
             echo 'Name: ' . $order->get_item_meta($item_id, '_wccf_pf_show', true) . '<br><br>';
            } elseif(isset($item_meta->meta['_wccf_pf_show2'])) {
             echo 'Name2: ' . $order->get_item_meta($item_id, '_wccf_pf_show2', true) . '<br><br>';
            }

        }
相关问题