Skip to content

Instantly share code, notes, and snippets.

@lukecav
Created May 26, 2023 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/628f18f6c324f526a80e8cd7ca5ee3d9 to your computer and use it in GitHub Desktop.
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
// 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