Answer the question
In order to leave comments, you need to log in
Variable product in the catalog. Add to cart button how to change the function?
Hello. I am looking for a solution to the following problem, I need the ability to add a variable product immediately to the cart from the product catalog without going to the product card. A variable product has a default variant. A variable product appears on the category page, then the user selects a variation from the drop-down list, then clicks "Add to cart" and gets to the product card page, but you just need the view cart button to appear and the person then continues to select products in the catalog.
Answer the question
In order to leave comments, you need to log in
I will sign the logic, if you know how to write code, then you can handle it.
1. Through the hook, display the select with child products via $product->get_children()
2. Then, when clicking add to cart, call WC()->cart->add_to_cart() and pass the necessary variation parameters there. Link to documentation https://docs.woocommerce.com/wc-apidocs/source-cla...
Use a small plugin:
https://wordpress.org/plugins/woocommerce-ajax-add...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question