0
votes

I want to just show a simple add to cart button at the bottom of a page. I can do so by using shortcodes:

[add_to_cart id="99"] or [add_to_cart_url id="99"]

The problem is that I want to then go to another URL that is not related to WooCommerce. It has to be customized depending on the page we are on.

An example would be:

  1. Intro Landing page (add to cart at bottom) a. Action: adds product 99 to cart then redirects to #2.
  2. Upsell page with 3 products on it a. Action: adds one of the three products to the cart and redirects to #3.
  3. Second Upsell page with 1 product on it a. Action: adds the product to the cart and redirects to #4.
  4. Checkout Page.

I was hoping there was a shortcode that I could use for Add to Cart and Redirect but can't find anything online. I have found a custom redirect option that woocommerce offers but it would set the redirect for all Add to Cart buttons.

I was thinking that there may be a way to create a function that expands the add to cart button shortcode so I can add a custom redirect URL to it.

For example: [add_to_cart id="99" redirect="../step2/"]

This can even be a URL that I can use in a link. I found that on this page under the section titled "URL: Add One Simple Product to Cart & Redirect to Any Page Afterwards" that says I should be able to just use:

href="http://yourdomain.com/your_custom_page/?add-to-cart=25"

It adds the product to the cart but then just redirects to the cart (I have AJAX add to cart buttons enabled).

Any ideas may help!

Thanks, Matt

1

1 Answers

0
votes

Using this works: http://yourdomain.com/your_custom_page/?add-to-cart=25

I just had to uncheck the box in WooCommerce Settings that says to go to cart when someone clicks add to cart and make sure AJAX links was checked