duandi8852752 2019-04-17 00:48
浏览 34

Woocommerce - 从电子邮件中的产品名称中删除变体

I am trying to resolve how I can remove Product Variations (Attributes/Meta) from the Product/Item title specifically when sending automated emails through WooCommerce.

I have successfully accomplished removing these attributes from titles and listing them below in the Cart, Checkout, My Account Order History, Creating Invoices & Packing Slips (WooCommerce PDF Invoices & Packing Slips). However, when I send emails they remain (they also remain in the title on the Admin Order Details page which is annoying but not the end of the world).

Disclaimer, I am new to WooCommerce and learning how to properly apply filters.

From my research I feel confident that I need to adjust the woocommerce_order_item_name filter but I'm not exactly sure what I need to adjust specifically.

I found a similar article, but it was referring to a very specific set of conditions: WooCommerce - Remove variation from product title in order details and email

Current Code:

 /* Woocommerce: Item Descriptions: Cart/Order - Removing attribute values from Product variation title */
add_filter( 'woocommerce_product_variation_title_include_attributes', 'variation_title_not_include_attributes' );
function variation_title_not_include_attributes( $boolean ){
    if ( ! is_cart() )
        $boolean = false;
    return $boolean;
}

 /* Woocommerce: Item Descriptions: Cart/Order - Display Product variation attributes label and values in separate rows */
add_filter( 'woocommerce_is_attribute_in_product_name', 'remove_attribute_in_product_name' );
function remove_attribute_in_product_name( $boolean){
    if ( ! is_cart() )
        $boolean = false;
    return $boolean;
}

 /* Woocommerce: Item Descriptions:  Checkout page - Remove the quantity from the product title */
add_filter( 'woocommerce_checkout_cart_item_quantity', 'remove_product_variation_qty_from_title', 10, 3 );
function remove_product_variation_qty_from_title( $quantity_html, $cart_item, $cart_item_key ){
    if ( $cart_item['data']->is_type('variation') && is_checkout() )
        $quantity_html = '';

    return $quantity_html;
}

 /* Woocommerce: Item Descriptions:  Checkout page - Add back the cart item quantity in a separate row */
add_filter( 'woocommerce_get_item_data', 'filter_get_item_data', 10, 2 );
function filter_get_item_data( $item_data, $cart_item ) {

    if ( $cart_item['data']->is_type('variation') && is_checkout() )
        $item_data[] = array(
            'key'      => __('QTY'),
            'display'  => $cart_item['quantity']
        );

    return $item_data;
}

 /* Woocommerce: Item Descriptions:  Remove Attributes in Packing Slip & Invoice */
add_filter( 'wpo_wcpdf_order_item_data', 'wpo_wcpdf_remove_variation_from_product_title', 10, 3 );
function wpo_wcpdf_remove_variation_from_product_title( $item_data, $order, $template_type ) {
    if ( !empty($item_data['product']) && $item_data['product']->is_type( 'variation' ) ) {
        $item_data['name'] = $item_data['product']->get_title();
    }

    return $item_data;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看