Viewing 6 replies - 1 through 6 (of 6 total)
  • I am also very interested in this for the same reason

    A format like this should work for either simple products or if the variation ID is uploaded to Google as the ID.

    https://example.com/checkout/?add-to-cart={id}

    Once you set the URL, there is a test button that you can use to try it out.

    If you are using the Google Listings & Ads plugin to sync products to merchant center, the solution suggested by @douglsmith will not work. The GLA plugin automatically prepends your product id with “gla_” before submitting to merchant center as item_id (seems unnecessary). So if your product id is “123”, then it will get an item_id of “gla_123” in merchant center.

    To be fair, @douglsmith solution does work if you had another implementation that uses the actual product id as item id and it could be helpful for a use case outside of merchant center checkout links.

    Seems like there should be a workaround by setting up an ID rule in merchant center, but I am too scared to try. Altering item ID after a product has been established could really mess up ad learning and/or search ranking. Another workaround I did investigate was setting the “checkout link template” at product level either manually or with feed rules, but neither of those are available in merchant center as of now.

    A true solution would be for the Google Listings & Ads plugin (created and managed by WooCommerce) to send the actual product id to merchant center. There is no option in the plugin to disable/edit the prepended “gla_” as of now, and even that would only hurt those of us who are already using the plugin (existing products would lose learning/ranking).

    If somebody knows whether setting up an ID rule will screw up ads/rankings, please chime in! That would be a simple way to get the @douglsmith solution to work on an account level, but the note that says “Note: After updating your ID rule, you may not be able to show ads or listings from that feed for several hours.” has me too scared to try.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @robertpurnomo,

    It seems that this has been marked as resolved. Have you managed to get this sorted, or do you still need help resolving this?

    If the issue continues, we’re here and happy to help you out further.

    Looking forward to your response!

    eaglejohn

    (@danielbenjamins)

    Following, I’m interested in this as well.

    danielstoelzner

    (@danielstoelzner)

    This code in your functions.php fixes this behavior:

    add_action('init', function() {
        if (isset($_GET['add-to-cart'])) {
            $value = $_GET['add-to-cart'];
            if (strpos($value, 'gla_') === 0) {
                $product_id = (int) substr($value, 4);
                $product = wc_get_product($product_id);
                if ($product && $product->exists()) {
                    WC()->cart->add_to_cart($product_id);
                } else {
                    wc_add_notice('Invalid product ID provided.', 'error');
                }
            }
        }
    });
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce product direct checkout URL, so shoppers can go directly to checkout’ is closed to new replies.