“销售徽章”没有销售价格
我正在WordPress上工作,我想进行一些销售徽章,但忽略了销售价格(只有常规价格)。
产品上的销售价格上的数字上,才能出现“销售徽章”
我已经尝试过几次,但是只有在我使用下面使用代码的
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
global $post,$product;
if ( ! $product->is_in_stock() ) return;
$sale_price = get_post_meta( $product->id, '_price', true);
$regular_price = get_post_meta( $product->id, '_regular_price', true);
if (has_term('one', 'product_cat', $product->ID)) {
return '<span class="onsale">one</span>';
} elseif (has_term('two', 'product_cat', $product->ID)) {
return '<span class="onsale">two</span>';
} elseif (has_term('three', 'product_cat', $product->ID) || empty($sale_price)) {
return '<span class="onsale">three</span>';
}
return '<span class="onsale">Sale</span>';
}
I'm working on woocommerce on wordpress, I want to make some sale badges but ignore the sales price (there are only regular prices).
I've tried it several times but the "sale badge" can only appear when I put the number on the sale price on the product
I use the code below
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
global $post,$product;
if ( ! $product->is_in_stock() ) return;
$sale_price = get_post_meta( $product->id, '_price', true);
$regular_price = get_post_meta( $product->id, '_regular_price', true);
if (has_term('one', 'product_cat', $product->ID)) {
return '<span class="onsale">one</span>';
} elseif (has_term('two', 'product_cat', $product->ID)) {
return '<span class="onsale">two</span>';
} elseif (has_term('three', 'product_cat', $product->ID) || empty($sale_price)) {
return '<span class="onsale">three</span>';
}
return '<span class="onsale">Sale</span>';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当产品开始销售时才应用过滤器本身。
您需要在检查产品是否出售之前覆盖发生的闪存销售动作。
首先,删除核心闪存销售挂钩。
然后,改用您的自定义销售功能。
然后使用
echo
而不是返回
The filter itself is applied only if the product is on sale.
You need to overwrite the flash sale actions that happen before checking if the product is on sale.
first, remove the core flash sale hooks.
then, add your custom sale function instead.
then use
echo
instead ofreturn