Our webshop needs a button added to every out-of-stock product page. I've tried adding the code below, but the button appears on all products, including those that are in stock. Can someone provide guidance on how to fix this issue?
Appreciate any help!
// Code to display an enquiry form on Woocommerce Single product pages
add_action( 'woocommerce_single_product_summary', 'enquiry_form', 30 );
function enquiry_form() { echo '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Request Price</button>'; echo '<div id="product_inq" style="display:none">'; echo do_shortcode('[wpforms id="1372"]'); echo '</div>'; }
add_action( 'woocommerce_single_product_summary', 'enquiry_form_1', 40);
function enquiry_form_1() {
?>
<script type="text/javascript">
jQuery('#trigger_cf').on('click', function(){
if ( jQuery(this).text() == 'Vraag de prijs op' ) {
jQuery('#product_inq').css("display","block");
jQuery("#trigger_cf").html('Close');
} else {
jQuery('#product_inq').hide();
jQuery("#trigger_cf").html('Request Price');
}
});
</script>
<?php
}