Paypal | Site Banner Q4 2024

Added by Latoya

Product Icon

Google for WooCommerce

Promote your products across Google - from Search to YouTube and beyond. So you can reach the right customers to make the most of your peak season.

Google Direct Checkout Option

I have received an invitation from google to enable direct checkout at free listing.

The problem is that I cannot integrate on account level due to the fact that the id includes gla_ then product id and if I have to add direct checkout then I have to go with website.com/?add-to-cart?={product_id} so in google the id is passed as gla_{product-id} therefore it is not possible on account level.

Another option provided by Google is to enable it by product level now the development team is requested to add one more field in the plugin named as [checkout_link_template].

This will help to sync with google and get it done on individual level.

Google support link is also mentioned below so you can get more insight about google feature.

https://support.google.com/merchants/answer/13580732#zippy=offer-level-url-formattingaccount-level-url-formatting

Author

shopisense

Current Status

Open

Last updated: August 22, 2023

7 comments

Log in to comment on this feature request.

  1. sparkliercouk says:

    Thanks @jsballarini I was having real problems with the gla_ prefix on the google product_id

    I had a couple of issues with the code provided, because our store is limited to one-off items. I found that the item added twice. I think the redirect was being treated as a second add_to_cart event.

    I made a couple of alterations that worked for me, and here is the amendment.

    As a note the checkout URL is,

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

    append the following to your child theme function.php. If you add it to the parent, it will be removed at the next update of the theme.

    add_action(‘template_redirect’, ‘remove_gla_prefix_from_add_to_cart_url’);

    function remove_gla_prefix_from_add_to_cart_url() {
    // Check if the ‘add-to-cart’ parameter is present in the URL
    if (isset($_GET[‘add-to-cart’])) {
    $add_to_cart = $_GET[‘add-to-cart’];

    // Check if the ‘add-to-cart’ parameter starts with ‘gla_’
    if (strpos($add_to_cart, ‘gla_’) === 0) {
    // Remove the ‘gla_’ prefix and update the product ID
    $product_id = str_replace(‘gla_’, ”, $add_to_cart);

    // Prevent duplicate adding by unsetting the parameter after redirect
    wp_safe_redirect(home_url(“/checkout/?add-to-cart=” . $product_id));
    exit;
    }
    }
    }

    The amendment I made checks to see if the item is already in the cart at the time of the redirect.

  2. vadgasiyasamjut says:

    Hello. Has anyone found [checkout_link_template] for woo commerce?

  3. jsballarini says:

    It worked for me:

    Open your functions.php os your active theme and add this:

    add_action(‘template_redirect’, ‘remove_gla_prefix_from_add_to_cart_url’);

    function remove_gla_prefix_from_add_to_cart_url() {
    // Check if the ‘add-to-cart’ parameter is present in the URL
    if (isset($_GET[‘add-to-cart’])) {
    $add_to_cart = $_GET[‘add-to-cart’];

    // Check if the ‘add-to-cart’ parameter starts with ‘gla_’
    if (strpos($add_to_cart, ‘gla_’) === 0) {
    // Remove the ‘gla_’ prefix and update the product ID
    $product_id = str_replace(‘gla_’, ”, $add_to_cart);

    // Redirect to the correct URL without the ‘gla_’ prefix
    wp_safe_redirect(add_query_arg(‘add-to-cart’, $product_id));
    exit;
    }
    }
    }

    Explanation:
    template_redirect: This hook runs just before WooCommerce processes the URL and loads the template, giving us the chance to modify the URL.

    isset($_GET[‘add-to-cart’]): Checks if the add-to-cart parameter is present in the URL.

    strpos($add_to_cart, ‘gla_’) === 0: Ensures that the add-to-cart value starts with the gla_ prefix.

    str_replace(‘gla_’, ”, $add_to_cart): Removes the gla_ prefix so that only the product ID is left.

    wp_safe_redirect(): Redirects the user to the same URL but with the corrected add-to-cart value without the prefix.

    This code should now handle the URL redirection in WooCommerce properly by removing the gla_ prefix before processing the add-to-cart parameter.

  4. claraea49220b6f says:

    1000% want this – adds a massive upside to the google merchant centre link.

  5. Marketing LAAIEND says:

    This is a simple upgrade with potentially big upside. No brainer.

  6. dropinprts says:

    this should be a feature!

  7. deidesigninc says:

    it will be nice to add this feature!

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.