从产品变体标题中删除属性值并将它们显示在单独的行中 [英] Remove attribute values from product variation title and show them on separate rows

查看:24
本文介绍了从产品变体标题中删除属性值并将它们显示在单独的行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想要的结帐页面:

I have a checkout page where I want to:

  • 从产品变体标题项中删除选定的产品属性值.
  • 也从商品标题中删除数量.
  • 在不同的行上显示不同的产品属性值,例如尺寸、颜色和数量,用于此产品变体项目.

我想在我的结帐页面上显示:

I want to display on my checkout page:

Aria 运动短裤 (产品标题)

颜色:灰粉色

尺寸:

数量: 1

取而代之的是:

有可能吗?我应该从哪里开始实现这一点?

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

推荐答案

UPDATED

1) 从 WooCommerce 3+ 开始,要从产品变体标题中删除属性值并将它们显示在单独的行中,需要使用这 2 个专用的简单挂钩(在结帐页面中).

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).

  • 从产品变体标题中删除属性值:
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;
}

  • 在单独的行中显示产品变体属性标签和值:
  • 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) 结帐页面 - 从产品标题中删除数量并将其重新添加到单独的行中.

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

    • 从产品标题中删除数量:
    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_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;
      }
      

      代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

      在 Woocommerce 版本 3+ 中测试并有效.您可能需要对样式进行一些更改……

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

      这篇关于从产品变体标题中删除属性值并将它们显示在单独的行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆