Product pages - Stay on the product page after adding products to the cart

Highlighted
New Member
7 0 0

I'm aware of what an AJAX is but I wasn't entirely looking for an AJAX solution in the first place. Although I wasn't looking for an AJAX solution, this is the solution I was looking for. To give you some background I coded a bar at the top of my website that gives the user (customer) a countdown for the amount of money they have to spend to get free shipping. I ideally would like that countdown to update as soon as the "Add to cart" button is pressed. The reason why I used this code is because it would allow my customer to continue shopping on the same page without having to click out of anything.

 

With this context, would it be possible to have this code refresh the page upon clicking the "Add to cart" button?

 

Thanks, Nate

0 Likes
Highlighted
Shopify Expert
142 0 28

Hi Nate! thanks for the extra info. You can add some extra code into the ajaxify script to tell it to update your free shipping progress bar without having to refresh the page. It needs to be specific for your theme and the classes of your bar, but it should be fairly simple if I know the class or ID of the shipping bar text. If you have a link to your site that I can see I may be able to help you add that code. 

 

0 Likes
Highlighted
New Member
7 0 0

To be clear all you need is the link and nothing else? The link is https://sugar-laine-cutters.myshopify.com/ 

 

Since I haven't opened the store to general public yet the password is: "rotlisberger"

 

Let me know if you need any extra info, thanks

 

-Nate

0 Likes
Highlighted
Shopify Expert
142 0 28

Hi Nate, 

I went to your site but I didn't see anything about free shipping in the bar at the top. For me it just says " Processing time: 1-3 business days" 

Can you help me find the area you want updated when someone adds to cart?

0 Likes
Highlighted
New Member
7 0 0

Yes sorry I should've explained it better to you. I have that message display before the user adds anything to the cart. If you add something to the cart and refresh your page it'll display the price required now. I could take away that message if that clears up confusion. 

0 Likes
Highlighted
Shopify Partner
452 59 71

@Nrotlisberger,

I think the price countdown is not working apparently and all we can see is the same message even after adding products to the cart.  I understand that you need a message there with a price countdown. I understand you also know AJAX then what is the actual issue? Do you need a solution of a simple page refresh on an addtocart? something similar to, like what update cart does on cart page?

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution

Skype : lokendra.panwar1
0 Likes
Highlighted
Shopify Expert
142 0 28

@Nrotlisberger  I see! did you write the script for that bar or is it an app?

You would need to add something like this to the ajax script inside this function

$.getJSON(_config.shopifyAjaxCartURL, function(cart) {

... past code in here (probably on line 102)

}

 

 

 var cartTotal = cart.total_price;
              var cartGoal = 3500; // your number times 100 
              if cartTotal >= cartGoal {
                $('.announcement-bar__message').html('Your order qualifies for free shipping!');
              } else {
                var cartDiff = cartGoal - cartTotal ;
                $('.announcement-bar__message').html('Add just '+Shopify.formatMoney(cartDiff, "{{ shop.money_format | remove: "'" | remove: '"' }}")+'to your cart to receive free shipping!');
              }

 

 

 

email me if you need more help mail@handhugs.com

 

0 Likes
Highlighted
New Member
7 0 0

Yes that's the issue. The message doesn't update at the top until you refresh the page. All I'm looking for is some sort of code to refresh the page when the "Add to cart" button is pressed. Either that or some type of code so that the message at the top doesn't need to be refreshed in the first place and auto-updates. I'm not too sure if the 2nd option is possible but all I need in its simplest form is a page refresh upon clicking the Add to cart button so that the user can see their new total as they add something to the cart instead of having to refresh the page manually. Thanks for the help,

 

Nate

0 Likes
Highlighted
Shopify Expert
142 0 28

did you try my code? It should work exactly how you want. 

0 Likes
Highlighted
New Member
7 0 0

I did try it yes, I'm not too sure if you had received my email but the code you had sent takes me to the cart page upon clicking the Add to cart button.

To be clear what did your code intend to do?

The code I've tried implementing does the same thing, takes me to the cart page. Although this is a worthy solution, I just dont want the user have to click out of the cart page every time they add something to the cart.

 

Nate 

0 Likes