简体   繁体   English

如何在购物车页面中显示产品属性名称

[英]How to show product attribute name in cart page

One of my favorite members helgatheviking , gave me a good solution of my previous question to remove the quantity field from cart page for specific product attribute . 我最喜欢的一位会员helgatheviking ,给了我一个很好的解决方案解决了我先前提出的问题 ,即从购物车页面删除特定产品属性的数量字段。 Below is the function given by her. 以下是她提供的功能。

add_filter( 'woocommerce_cart_item_quantity', 'remove_cart_item_quantity', 10, 2 );
function remove_cart_item_quantity( $product_quantity, $cart_item_key ){
    $cart_item = WC()->cart->cart_contents[ $cart_item_key ];
    if( $cart_item['data']->is_type( 'variation' ) ){
        $attributes = $cart_item['data']->get_attributes();
        // var_dump( $attributes );
        if( array_key_exists( 'color', $attributes ) ){
            $product_quantity = '';
        }
    }
    return $product_quantity;
}

Now the $product_quantity; 现在$product_quantity; return a blank string. 返回一个空字符串。

Is it possible to show the name instead of Blank. 是否可以显示名称而不是空白。 $product_quantity = ''; What should I replace ? 我应该更换什么? If Selected product has color Green The $product_quantity; 如果所选产品的颜色为绿色,则$product_quantity; should return green. 应该返回绿色。 EXAMPLE: $product_quantity = '$color'; 示例: $product_quantity = '$color'; How could I get the color string from product attribute which in the cart. 如何从购物车中的产品属性获取颜色字符串。

I Solve this actually $_pname = WC()->cart->get_item_data( $cart_item ); 我实际上解决了这个$_pname = WC()->cart->get_item_data( $cart_item ); So you can use $product_quantity = str_ireplace( 'Choose Quantity:', '',$_pname) ; 因此,您可以使用$product_quantity = str_ireplace( 'Choose Quantity:', '',$_pname) ;

add_filter( 'woocommerce_cart_item_quantity', 'remove_cart_item_quantity', 10, 2 );
function remove_cart_item_quantity( $product_quantity, $cart_item_key ){
    $cart_item = WC()->cart->cart_contents[ $cart_item_key ];
    if( $cart_item['data']->is_type( 'variation' ) ){
        $attributes = $cart_item['data']->get_attributes();
        $_pname = WC()->cart->get_item_data( $cart_item );
        if( array_key_exists( 'choose-quantity', $attributes ) ){
            $product_quantity = str_ireplace( 'Choose Quantity:', '',$_pname) ;
        }
    }
    return $product_quantity;
}

Output: 输出: 输出Cart.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Magento如何在产品页面中显示产品属性? - Magento how to show product attribute in product page? WooCommerce如何在购物车页面上一次显示产品类别? - WooCommerce how to show product category once on cart page? 如何在magento的购物车页面中显示捆绑产品的所有子产品 - How to show all child products of bundle product in cart page in magento 如何在结帐页面上显示当前购物车产品的详细信息 - How to show current cart product's details on checkout page 在 Woocommerce 购物车页面上显示特定的产品属性 - Display specific product attribute on Woocommerce cart page Woocommerce:如何在标题上显示产品属性名称和类别名称 - Woocommerce: How to show Product Attribute name and Category name on title Woocommerce 在购物车页面中显示产品品牌 - Woocommerce show product brand in cart page Woocommerce:如何在类别页面中的标题上显示产品属性名称,并通过地址栏上的“?pa_attribute=”“过滤”产品 - Woocommerce: How to show Product Attribute name on title when in a category page and "filtering" products via '?pa_attribute=' on address bar 在 Woocommerce 购物车页面中的购物车项目名称后添加产品 ID - Add the product ID after the cart item name in Woocommerce cart page 如何将产品页面上输入的文本框值显示到结帐和购物车页面 - how can i show the textbox value entered on product page to checkout and cart page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM