首页 > 解决方案 > Show product attribute as price suffix in cart and checkout page

问题描述

This is my first post here in the community. I'm new to coding and need help to display a product attribute as a price suffix on the cart and checkout page. I've already managed to do this on the individual product page but I'm struggling with the cart and checkout page.

The code I'm trying to use is this:

add_filter( 'woocommerce_cart_item_price', 'fx_price_unity_suffix', 10, 2 );
  
function fx_price_unity_suffix( $price, $product){
    $text = $product->get_attribute('pa_unity');
    return $price . $text;
}

The error I believe is in the way I get the product attribute in the code, but I don't know another way to call the attribute. As I mentioned, I'm new to codes and I'm still learning. Thanks for everyone's attention and help.

标签: phpwordpresswoocommercecheckout

解决方案


推荐阅读