Reputation: 81
How can I display the regular price and not discount price on my product listing for a specific category? It always shows me the discount price.
Here is my code:
function filter_woocommerce_get_regular_price() {
global $product;
if (is_product_category ('book-fair')) {
return $product->get_regular_price();
}
return $product->get_sale_price();
}
I'm far from the solution?
Upvotes: 0
Views: 1156
Reputation: 253784
The hook woocommerce_get_regular_price
is obsolete and deprecated. Try the following instead:
// 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;
}
Code goes in functions.php file of your active child theme (or active theme). It should work.
Upvotes: 1