Add multiple dropdown selections to cart on submit?
-
I’m using the Product List Field plugin to populate dropdowns with WooCommerce products. I can add one dropdown selection to cart on submit, but I can’t figure out how to add products from multiple dropdowns to the cart on submit. I will have multiple dropdowns on one form either as multistep or via tabs.
I’ve read through threads on adding multiple items to the cart in a url, such as this stackoverflow one, but all the solutions are in php and I can’t get them to work with my JS.This is the code I’m using to add a product to the cart from a single dropdown:
add_action( 'wp_footer', 'custom_footer' ); function custom_footer() { ?> <script type="text/javascript"> document.addEventListener( 'wpcf7submit', function( event ) { if ( '1000' == event.detail.contactFormId ) { var data = document.getElementsByName('dropdown1'); var product1 = data[0][data[0].selectedIndex].getAttribute('data-pro_post_id'); location.replace('https://www.example.com/cart?add-to-cart=' + product1); } }, false ); </script> <?php }
I know there are premium plugins that integrate WooCommerce with CF7, and some may provide this functionality, but I’m obviously looking for a free solution.
- The topic ‘Add multiple dropdown selections to cart on submit?’ is closed to new replies.