在购物车和结帐页面中将产品属性显示为价格后缀

时间:2021-07-25 22:45:16

标签: php wordpress woocommerce checkout

这是我在社区中的第一篇文章。我是编码新手,需要帮助才能在购物车和结帐页面上将产品属性显示为价格后缀。我已经设法在单个产品页面上执行此操作,但我在购物车和结帐页面上遇到了困难。

我尝试使用的代码是这样的:

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

我认为错误在于我在代码中获取产品属性的方式,但我不知道调用该属性的另一种方式。正如我所提到的,我是代码新手,我仍在学习。感谢大家的关注和帮助。

0 个答案:

没有答案