mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
11 lines
607 B
Text
11 lines
607 B
Text
// 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 );
|