Skip to content
Advertisement

Custom “Terms and Conditions” acceptance checkbox in Cart page Woocommerce

Works on small home project, and want to add checkmark option bellow “Proceed to Checkout” button into Cart page into my Woocommerce site. I found this function, that is add that option:

JavaScript

But seems that something is not fine with this function, because no matter if checked or not, customer can proceed to checkout page. I want to ensure that ONLY customers who will check the checkbox, can proceed to checkout. In opposite, warning message will be shown at top.

enter image description here

Can someone to tell me where is issue with this function or to point me to some working solution? Thanks in advance. This is image how currently looks with this function i posted before.

Advertisement

Answer

The following code will work in cart page for your privacy policy checkbox using mandatory jQuery code to make it work as “proceed to checkout” button is just linked to checkout page without submitting any data.

The code will disable the button on start:

enter image description here

It use “Sweet alert 2” JS message to display an error message on button click when the checkbox is not checked:

enter image description here

The complete code:

JavaScript

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

Sweet Alert Two documentation

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