Woocommerce ho to change action for backorder button?

How to make the Formcraft contact form be called when clicking the pre-order button? (only pre-order products) Thank you! Unfortunately I did not find any information in the wordpress CODEX on how I can influence the add to cart button via functions.php to change button link only for products on-backorder.

Comment (1)

Jese Leos

September 1, 2024

Verified user

Please check this code add_filter('woocommerce_loop_add_to_cart_link', 'custom_pre_order_button', 10, 2); add_filter('woocommerce_single_product_summary', 'custom_pre_order_button_single', 30); function custom_pre_order_button($button, $product) { if ($product->is_on_backorder()) { $button = '<a href="#" class="button pre-order-button" onclick="openFormcraftForm()">Pre-order Now</a>'; } return $button; } function custom_pre_order_button_single() { global $product; if ($product->is_on_backorder()) { remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); echo '<a href="#" class="button pre-order-button" onclick="openFormcraftForm()">Pre-order Now</a>'; } } function openFormcraftForm() { ?> <script type="text/javascript"> function openFormcraftForm() { jQuery('#formcraft-form-id').trigger('click'); } </script> <?php }

You’ll be in good company