从产品变体标题中删除属性值,并在单独的行中显示它们 [英] Remove attribute values from product variation title and show them on separate rows
问题描述
我有一个要在其中结帐的页面:
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?
推荐答案
更新
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屋!