Skip to content

Instantly share code, notes, and snippets.

@mio31337
Created June 27, 2023 15:46
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 mio31337/d152f117d282bd78fe7e422d9c42f47d to your computer and use it in GitHub Desktop.
Save mio31337/d152f117d282bd78fe7e422d9c42f47d to your computer and use it in GitHub Desktop.
/**
* 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