Skip to content
Advertisement

Product custom checkbox option that changes Woocommerce cart item price

The following code displays a custom checkbox before add to cart button on single product pages:

JavaScript

Now I would like to trap/capture this checkbox option in Woocommerce session and then make a custom price calculations in the following code:

JavaScript

What is missing is the part that will capture the checkbox option to set it in sessions, like:

JavaScript

Any help is appreciated.


Admin Part of the code →

JavaScript

Outputting HTML on Product Page →

JavaScript

Advertisement

Answer

You don’t need to use any session for that. Use woocommerce_add_cart_item_data filter hook like:

JavaScript

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

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