Created
June 27, 2023 15:46
-
-
Save mio31337/d152f117d282bd78fe7e422d9c42f47d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Function to display variations sale prices only when a variation on sale is selected | |
*/ | |
function action_wc_before_single_variation() { | |
?> | |
<script type="text/javascript"> | |
(function($){ | |
// Check for the show_variation event that triggers when a variation is selected. | |
$('form.variations_form').on('show_variation', function(event, data){ | |
//If variation is on sale, display the sale badge | |
if(data.display_price < data.display_regular_price){ | |
// $(".product-type-variable .nm-single-product-summary-col .onsale").css("display", "block"); | |
$(".product-type-variable .onsale").css("display", "block"); | |
} | |
//Otherwise hide the sale badge | |
else { | |
// $(".product-type-variable .nm-single-product-summary-col .onsale").css("display", "none"); | |
$(".product-type-variable .onsale").css("display", "none"); | |
} | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} | |
add_action( 'woocommerce_before_single_variation', 'action_wc_before_single_variation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment