在WooCommerce购物篮页面上显示产品属性



我负责一个网站(https://www.artyapple.com/)并且在查看购物篮时不会显示产品属性。

我试过"WooCommerce显示属性"插件,但它不起作用。我也尝试了在这个网站上找到的一些代码,但都没有成功。

我正在运行WordPress和WooCommerce的新版本,但我的主题确实过时了——所有者不会更新主题。

如果有任何帮助或建议,我将不胜感激。谢谢,

Paul

下面的过滤器应该获取购物车中每个产品的属性,并将它们的名称添加到数组中。然后,数组在购物车页面中的产品名称下方以逗号分隔的值输出。

修改自:在wooccommerce 3 中的购物车页面上显示变体的产品属性

add_filter('woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data($item_name, $cart_item, $cart_item_key)
{
$product = wc_get_product($cart_item['product_id']);
$attribute_names = array();
// Get product attributes
$attributes = $product->get_attributes();
if (!empty($attributes)) {
foreach ($attributes as $attr) {
$attribute_names[] = $attr->get_name();
}
$item_name .= '<p class="item-category" style="margin:12px 0 0; font-size: .875em;">
<span class="values">' . implode(', ', $attribute_names) . '</span>
</p>';
}
return $item_name;
}

最新更新