How to display variations selection error message in woocommerce shop page?

The variation selection error message show in woocommerce website display in WooCommerce product single page, if you are using variations on product page and not selected before directly click on add to card button in Woocommerce each product in the shop, so will need to error display/show on the woocommerce archive shop page.

Woocommerce for variation selection error message display in category and archive pages

Always use child theme any wordpress website and copy below code and add this code in your header.php and in woocommerce shop page.
Use this below jQuery for variation selection error message show in page and do change classes according used in theme shop page-

<script>
jQuery( function($){
$( '<p id="show_error">select variation options</p>' ).insertBefore( ".single_variation_wrap" );
$('#show_error').hide();
$('.single_add_to_cart_button').on('click',function(e){
if ( $( this ).is('.disabled') ) {
e.preventDefault();
if ( $( this ).is('.wc-variation-selection-needed') ) {
$('#show_error').show();
setTimeout(function () {
$('#show_error').hide();
}, 5000);
return false;
} if ( $( this ).is('.wc-variation-is-unavailable') ) {
e.preventDefault();
return false;
}
} });
});
</script>

Post a Comment

0 Comments