这是我的 WordPress 配置(刚刚升级了一切,所以一切都是最新的):
WordPress:5.4
WooCommerce:4.0.1 WooCommerce
折扣规则:1.9.7
WooCommerce 配置的折扣规则,每个数量块:
1-4:10%
5-24:20%
25-99999:30%
这在商店中运行得非常好,商店甚至可以通过折扣正确获得订单。问题是我想删除 SALE!来自产品的徽章,因为它是自动添加的,因为 1-4 个数量块,这意味着根据配置默认 10% 的站点范围折扣。
现在,这是我在主题的 functions.php 中的代码
function wc_custom_replace_sale_text($html, $post, $product) {
if ($product->is_on_sale()) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
return '<span class="onsale force-display">' . $sale_price . '</span>';
}
}
add_filter( 'woocommerce_sale_flash', 'wc_custom_replace_sale_text', 10, 3 );
问题:无论我尝试什么,我总是得到$product->get_sale_price()
结果总是0。而且,奇怪的是$product_is_on_sale()
结果是true
。
因此,我无法找到产品折扣,因此无法删除 1-4 数量块的销售标签。