This code adds a product to the cart when another product is added and matches the quantity. Example :
- If 1 product named A is added to cart, another (addon ) product named B will be added.
- If 5 products named A are added to cart, 5 ( addon ) products named B will also be added.
The addon can be a free product or a paid product, it doesn’t matter.
Shows a product quantity of 5 demo products added to the cart which auto adds 5 addon products based on the product I.D added to the input field for the main product.
Tested using the Twenty Twenty default theme for WordPress however will work in any WordPress theme running WooCommerce.
Copy & paste the PHP code to the end of your child themes functions file or custom functionality plugin.
You can then grab the product I.D for your addon product to the input field on the edit product screen as seen in the demo video.
You must be logged in to post a comment.