Skip to content
Advertisement

WooCommerce: Avoid checkout If all cart item custom fields are not filled in

I wrote a function that disables the ordering button when additional fields (with display in cart) in each of the products have not been completed (fields appear only if there are more than 2 items in the cart).

JavaScript

But it only works when the page is refreshed in the browser.

How can I make the function refresh every time something is entered in the text field assigned to the product and the section with the order button will be refreshed with ajax?

Below is the code that is responsible for adding notes:

Javascrit code saved under update-cart-item-ajax.js file name (custom file):

JavaScript

PHP code saved in active theme functions.php file:

JavaScript

Advertisement

Answer

In your case, to avoid checkout, use instead woocommerce_checkout_process dedicated hook like:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

enter image description here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement