php - 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.
解决方案
推荐阅读
- php - 首先显示最后一个错误而不是第一个(php)
- r - 对 R 中的文件名向量进行排序,因为 Windows 会对它们进行排序?
- python - 在运行烧瓶应用程序之前终止给定端口上的进程
- c# - 在具有许多实例以获得内存/性能优势的对象中是否使用静态类?
- python-3.x - 函数中的函数出现未定义错误
- android - 视图绑定:有没有一种方法可以在给定布局 id 的情况下对布局进行一般膨胀?
- python - 无法将 for 循环用作列表理解
- unicode - Windows和Linux之间的特殊char比较行为差异
- c++ - 哪些存储类型不完整的 STL 数据结构可以用作类成员?
- ruby-on-rails - 我应该使用什么将 Rails 应用程序与远程服务器连接起来?