dsztc99732 2017-11-19 13:55
浏览 49
已采纳

从产品变体标题中删除属性值,并在不同的行上显示它们

I have a checkout page where I want to:

  • Remove selected product attribute values from product variation title item.
  • Remove the quantity from item title too.
  • Display the different product attribute value such as size, color and the quantity on different rows, for this product variation item.

I want to display on my checkout page:

Aria Sport Shorts (the product title)

Color: Dusty Pink

Size: Small

QTY: 1

Instead of this:

How it looks now

Is it possible? Where I should start to make this real?

  • 写回答

1条回答 默认 最新

  • dtjw6660 2017-11-19 18:19
    关注

    UPDATED

    1) Since WooCommerce 3+, to remove attribute values from Product variation title and to display them in a separate row will need to use this 2 dedicated simple hooks (in checkout page).

    • 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;
    }
    
    • 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;
    }
    

    2) Checkout page - Remove the quantity from the product title and add it back in a separate row.

    • 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;
    }
    
    • 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;
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested in Woocommerce version 3+ and works. You should maybe need to make some styling changes…

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False