php - 如何在 WooCommerce 中显示特定产品类别的正常价格
问题描述
如何在特定类别的产品列表中显示正常价格而不是折扣价格?它总是向我显示折扣价。
这是我的代码:
function filter_woocommerce_get_regular_price() {
global $product;
if (is_product_category ('book-fair')) {
return $product->get_regular_price();
}
return $product->get_sale_price();
}
我离解决方案还远吗?
解决方案
该钩子woocommerce_get_regular_price
已过时且已弃用……请尝试以下操作:
// Custom regular price for specific product categories
add_filter('woocommerce_product_get_price', 'filter_woocommerce_product_get_price', 10, 2);
function filter_woocommerce_product_get_price( $price, $product ) {
if ( has_term( array('book-fair'), 'product_cat', $product->get_id() ) && $product->is_on_sale() ) {
return $product->get_regular_price();
}
return $price;
}
代码在您的活动子主题(或活动主题)的functions.php 文件中。它应该有效。
推荐阅读
- c# - 具有受保护设置器的可空属性,推断为朋友(内部)字段
- android - 所有产品风味都连接到一个构建变体
- google-analytics - Google Analytics - 搜索类别的高级搜索过滤器
- reactjs - 重定向链接到地图路线
- javascript - JavaScript new formData().append 不适用于上传的文件
- raku - 语法行为是否在 6.c 和 6.d 之间中断?
- pdf - 以 PDF 格式导出多个剑道网格
- javascript - 如何使用 Javascript 在移动 Safari 和所有其他浏览器上录制音频?
- python-2.7 - 我将如何用更长的密码来加密这个字符串?
- r - Vectorize 函数对两个参数的函数进行操作