• Resolved scottl31

    (@scottl31)


    This is related to my request at:

    https://www.ads-software.com/support/topic/custom-post-add-to-cart-buttons-editing/

    which was marked resolved, but was not resolved at all.

    So doing the add to cart url with ID, I made a link like:

    https://yourgroovydomain.com/?add-to-cart=123

    And it of course loads the item in the cart. But the problem is that the site thinks that “?add-to-cart=123” is a page and tries to go there, and since there is no such page, it just goes to the home page. I was using a 404 to homepage plugin so I disabled it, but it still just goes to the home page.

    Is there a way to click this link and keep the user on the page that it was clicked on?

    I actually found that it will go back to or “stay” on the page if I do:

    https://yourgroovydomain.com/this-page/?add-to-cart=123

    But one problem with this is that if the user hits the back button (for whatever reason) the item gets loaded in the cart again. While this isn’t bad, it’s just not ideal.

    Some kind of a combination that would go like this would be great:

    https://yourgroovydomain.com/?add-to-cart=123 —> https://yourgroovydomain.com/this-page/

    But then in either of the last two examples, I don’t know in advance what the name of the page is for the /this-page/ part, because it gets automatically created when importing products from our database. So I would need something that effectively does this:

    get-current-url/?add-to-cart=123

    I know this is a lot, but it seems like the last thing I can try.

    Thanks!

Viewing 15 replies - 1 through 15 (of 18 total)
  • Laurena Rehbein

    (@lrehbein)

    Automattic Happiness Engineer

    Hi scottl31,

    It’s not exactly what you are trying to do, but maybe a workaround:

    On your site’s WooCommerce settings, under the Product tab, you can have it set so that a user is redirected to the cart after a successful addition to the cart.

    If you use the URL and they then go to the cart, if they hit the “back” button, they do end up right back on the page the URL was on.

    It’s a bit more graceful than ending up on the homepage after adding to the cart.

    Thread Starter scottl31

    (@scottl31)

    Well, that doesn’t work because taking them to the cart assumes they are done shopping. I want them to go to the cart when they want to, not just because they added an item. I personally hate it when a site takes me to the cart when I add an item.

    So do you know if any of your colleagues might know more specifically how to do what I want?

    Thanks!

    Have you tried the WooCommerce shortcode:
    [add_to_cart id=”3890″]
    The shortcode senses the page that its being used on and so is able to construct the link to be able stay on the same page.

    You may need to style the output to suit your needs.

    Thread Starter scottl31

    (@scottl31)

    I tried but it doesn’t give me anything. What “styling” is required?

    What should happen is that it makes a button in a box and when you click the button, it generates the url of the page its on + the add_to_cart querystring. The product is added to the cart and the page reloads to the same page.

    The styling depends on what you want it to look like. However, if it doesn’t work for you, there’s no point worrying about styling.

    Ensure you are using straight quotes around the id, not smart quotes.

    Thread Starter scottl31

    (@scottl31)

    That was it. The quotes were bad. Funny they looked straight.

    So this worked, but the button is no good because it takes me back to the problem I originally started the previous post for. That got closed but I never resolved anything.

    If you wouldn’t mind maybe skimming that last thread, so you can see my problem, maybe that would help.

    https://www.ads-software.com/support/topic/custom-post-add-to-cart-buttons-editing/

    Laurena Rehbein

    (@lrehbein)

    Automattic Happiness Engineer

    @lorro that worked perfectly! Product added to the cart, user remains on the original page. Great solution!

    Thread Starter scottl31

    (@scottl31)

    No. Sigh. It puts me back to beginning. Please read my last post. Thanks.

    Is this product a variable-type product then? If so you can’t use the shortcode. Its only for simple products. Can you make 3 simple products, and put the add-to-carts in a row, so:

    Hard: [add_to_cart id=”101″] Soft: [add_to_cart id=”102″] eBook: [add_to_cart id=”103″]

    That will be the easiest if you don’t want to code. If its a variable product come back, but the fix will be tricky and a certainly a bit codey.

    Without coding, we can’t change the button text to the product attribute. We can change the button text to “Add to basket” for example, instead of “Add to cart”, but I take it that’s not what you want.

    If its a variable product, you can’t have a drop-down on the add-to-cart. That would be more recoding than you’d get here. You can have a drop-down if you insert the whole page, but I read you don’t want that.

    You may need to compromise if you want to avoid hiring a developer.

    Thread Starter scottl31

    (@scottl31)

    Well, I got real close with this url way of doing it since my boss was saying let’s just make it a link like “Buy eBook $6.00”

    And it really is pretty much working, except I think I just need to know how to have the link have some kind of code that would insert the current page’s url.

    Do you know anything like that? I googled for it, but everything I found, I couldn’t get to work.

    Try:
    <a href="?add_to_cart=3890">Buy eBook $6.00</a>

    In the absence of a url, the browser assumes the current page. Don’t know if this works in all browsers and devices. I expect it will.

    Or for a variable product:
    <a href="?add-to-cart=1175&variation_id=1184&attribute_pa_size=x-large&attribute_pa_colour=white">Buy eBook $6.00</a>

    where 1175 is the parent product id. I think the attribute_pa bit is different for ad-hoc attributes, not tested.

    Thread Starter scottl31

    (@scottl31)

    I just learned this week about leaving the url empty. Not sure why I didn’t think of it.

    At first your code didn’t work and it took me a while to figure out you used underscores instead of dashes.

    add_to_cart=

    Anyway, I’m going to put this through my whole process, so don’t close out this thread yet.

    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Related to the original post.

    I have several pages each with multiple products in a list. (300+)

    When the client adds an item, it always opens the cart or redirects to another page depending on the plugin I use to show the list of products (Quickster in my case)

    I simply want the clients to be able to add selected items to the cart, from mutiple pages, without any redirects. Then after the client has completed their order THEN they go to the cart process.

    Have spent 3 days trying to find a solution. Nada

    Wordpress with Divi, latest versions

    Thanks!

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Click add to cart url, but stay on page?’ is closed to new replies.