$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce: How can I add a certain product to the cart and redirect to the cart from a non-shop page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce: How can I add a certain product to the cart and redirect to the cart from a non-shop page?

matteradmin10PV0评论

I want to promote a certain product on a non-shop page. I want to have a Buy now link on that page, which, when clicked, would add the product to the cart and automatically reload the page and redirect the customer to the cart. This should be done only for that certain product and should not be enabled for all products (so the Redirect to the cart page after successful addition option should NOT be set to TRUE).

I want to promote a certain product on a non-shop page. I want to have a Buy now link on that page, which, when clicked, would add the product to the cart and automatically reload the page and redirect the customer to the cart. This should be done only for that certain product and should not be enabled for all products (so the Redirect to the cart page after successful addition option should NOT be set to TRUE).

Share Improve this question asked Oct 18, 2018 at 19:33 manifestormanifestor 3136 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can create "add to cart" links for WooCommerce using this pattern on simple links:

http://example/cart/?add-to-cart=<product ID>&quantity=<number of quantity>

This example will work with simple products.
If you want to use products with variations you need to add some more values to the URL like:

http://example/cart/?add-to-cart=123&variation_id=456&attribute_pa_colour=black

If you enter the slug of the cart page in this url, here: /cart/, it should redirect to the cart.

To add a product to the cart without redirecting:

http://example/?add-to-cart=<product ID>
Post a comment

comment list (0)

  1. No comments so far