WooCommerce Add to Cart - Redirect to URL - wordpress

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:
Intro Landing page (add to cart at bottom)
a. Action: adds product 99 to cart then redirects to #2.
Upsell page with 3 products on it
a. Action: adds one of the three products to the cart and redirects to #3.
Second Upsell page with 1 product on it
a. Action: adds the product to the cart and redirects to #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

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

Related

Add continue shopping button at woocommerce store category

Help me I'm looking around, but I still don't find what I need, add another button on my woocomerce store page with the option to add to cart and continue shopping without leaving the page
Here's an example of what I need:

How to skip checkout page Woocommerce?

Tell me pls how to skip checkout page Woocommerce?
A page where a person simply has to click the "place order" button, since the rest of the data is substituted itself.
After clicking it is redirected to the payment gateway...
How do I skip this formality by clicking one button and redirect them straight to the payment gateway?
Payment gateways is part of the WooCommerce checkout page. Do you have any payment gateways set up? May be you are referring to skipping the cart page and going to the checkout. Here's a great tutorial to do that: https://www.webroomtech.com/woocommerce-skip-cart-and-go-to-checkout/
add_filter('add_to_cart_redirect', 'webroom_redirect_add_to_cart');
function webroom_redirect_add_to_cart() {
global $woocommerce;
$cw_redirect_url_checkout = $woocommerce->cart->get_checkout_url();
return $cw_redirect_url_checkout;
}
add the above code to functions.php file and save it. From now on every time a user clicks the add-to-cart button it will be redirected to the checkout page.

How to add total sum to woocommerce cart section

I customized the "checkout" page and added cart section to that page.(Just copy and paste cart table from "cart" to "checkout" page)
I'm using storefront child theme and custom "cart","checkout" page templates are in here.
child-theme/woocommerce/cart/cart.php
child-theme/woocommerce/checkout/form-checkout.php
What I want is to add the total sum section below cart table. Something like this.
How can I handle this one?
For the total part WooCommerce has another template called "cart-totals.php".
So you might need to add its content too.

Woocommerce add to cart and redirect to Custom URL - Different for each link

So I am using a link on this page: https://www.revealio.com/make-brand-come-alive/ (yellow button).
The link is supposed to add the product to the cart and then send them to the next step in the sales funnel.
For the link URL I used:
https://www.revealio.com/help-creating-video?add-to-cart=4951
and
https://www.revealio.com/help-creating-video?add-to-cart=4951&quantity=1
Full link code is:
YES! MAKE MY BRAND COME ALIVE!
I found this code here: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/
If you need to see the cart (we are still redesigning these pages) you can go here in a seperate browser tab to see how it updates: https://www.revealio.com/cart/
The problem is that it is adding 2 products to my cart instead of 1.
How can I get this to just add one of my products to the cart and move on?
Here is something new I found out. If I just go directly to the link it only adds one product. If I click on the link in the page (https://www.revealio.com/make-brand-come-alive/) it adds 2 products. It does the same for a button or a text link.
Use the shortcodes provided by WooCommerce to render the add to cart links. https://docs.woocommerce.com/document/woocommerce-shortcodes/
[add_to_cart_url id="99"]
I found it!
It needs a / before the ?
https://www.revealio.com/help-creating-video/?add-to-cart=4951
I was using: https://www.revealio.com/help-creating-video?add-to-cart=4951 which gave two item in the cart.

Drupal Commerce Ajax cart with added fields

Sorry for the really bad title but wasn't sure how to describe my problem in 10 words.
I have drupal commerce and have made a view that displays the cart contents on top of the checkout page.
Quantity is a text field so it is editable and I have an update button. Unfortunately when I press the update button, naturally the whole checkout page tries to submit. Is there a way to intercept the update button and just refresh the cart with ajax?
Moreover, if I can do that, I want a number of text fields (as many as the quantity number entered) to appear underneath the cart so the user can enter different values on each of them (each referring to the products about to be bought).
Drupal Commerce Cart does this - sort of.. http://drupal.org/project/dc_cart_ajax
It works fine on the cart page, though I too am trying to combine these pages to cut down on the 'checkout steps'. Though it is the same view as the /cart page and I get an ajax refresh indicator it doesn't actually update the cart on the checkout page.
There is a issue related to that, you can subscribe: http://drupal.org/node/1443470
You can disable the Shopping cart contents using the checkout settings. Modify the Shopping Cart View to add a block display and add modify the contextual filter by providing default value using PHP:
if (arg(0) == 'checkout') return arg(1);
else return null;
Add the new Shopping cart block dispplay only on the checkout page and here you go.

Resources