Woocommerce Mini Cart Widget产品价格优先 [英] Woocommerce Mini Cart Widget product price override

查看:83
本文介绍了Woocommerce Mini Cart Widget产品价格优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Woocommerce Mini Cart Widget中更改产品价格?我已经使用 WooCommerce:将产品添加到购物车的提示覆盖购物车中的价格价格覆盖?但它只适用于购物车页面。小部件中的价格不会更改。

is it possible to change product price in Woocommerce Mini Cart Widget? I've overrided price in cart using tips from WooCommerce: Add product to cart with price override? but it only works for cart page. Prices in widget are not changed.

推荐答案

这是我将免费产品的价格设置为0的方式:

This is how I set price to 0 for free products:

function set_free_items_price( $price, $cart_item, $cart_item_key ) {

     $returned_item_price = $cart_item['data']->get_price();

     if (isset($cart_item['free_item']['value'])
         && $cart_item['free_item']['value'] == true) {
         $returned_item_price = 0;
     }

     return get_woocommerce_currency_symbol() . $returned_item_price;
}

我在类中挂钩,所以它的钩子看起来像这样:

I hooked inside class, so it hook looks like this:

add_filter( 'set_free_items_price', array(__CLASS__, 'woocommerce_cart_item_price_filter'), 10, 3 );

但是如果你使用它作为程序函数,你的钩子应该是这样的:

But if you are using it as procedural function, your hook should look like this:

add_filter( 'set_free_items_price', 'woocommerce_cart_item_price_filter', 10, 3 );

请注意,这也会影响普通购物车中的 price 行。
并且,如果您没有看到迷你购物车中的更改,请尝试在常规购物车页面上更新购物车,然后返回并再次检查迷你购物车价值是否已更改。

Keep in mind this is also affecting price row in regular cart. And, if you are not seeing changes in mini cart, try to update cart on regular cart page, and the go back and check again if mini-cart values has been changed.

这篇关于Woocommerce Mini Cart Widget产品价格优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆