Created
May 26, 2023 20:09
-
-
Save lukecav/628f18f6c324f526a80e8cd7ca5ee3d9 to your computer and use it in GitHub Desktop.
Remove the sales price and use regular price when the stock is zero in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove sale price and use regular price when stock is 0 | |
function remove_sale_price_on_zero_stock( $price, $product ) { | |
// Check if the product is on sale and has stock | |
if ( $product->is_on_sale() && $product->get_stock_quantity() <= 0 ) { | |
$regular_price = $product->get_regular_price(); | |
$price = wc_price( $regular_price ); // Use regular price instead of sale price | |
} | |
return $price; | |
} | |
add_filter( 'woocommerce_product_get_price', 'remove_sale_price_on_zero_stock', 10, 2 ); | |
add_filter( 'woocommerce_product_get_regular_price', 'remove_sale_price_on_zero_stock', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment