Integrate Google Pay WooCommerce
August 26, 2025 · AI Conversations
# Option A (recommended): via Stripe (or WooCommerce Payments)
This is the fastest and most stable path. Stripe (and WooCommerce Payments, which uses Stripe under the hood) exposes Google Pay as a **Payment Request Button**.
### 1) Install & connect
– Install **one** of:
– **WooCommerce Payments** (easy, official)
– **Stripe Gateway for WooCommerce** (official Stripe plugin)
– Connect your account (onboarding flow).
### 2) Enable Google Pay / Payment Request Button
– In **WooCommerce → Settings → Payments**:
– For **WooCommerce Payments**: Payments → **Express checkouts** → toggle **Google Pay** on.
– For **Stripe**: Stripe settings → **Payment Request Buttons** → enable, and select where to show (Product, Cart, Checkout).
– Make sure your **store currency** and **country** are supported by Google Pay and Stripe.
– Site **must be HTTPS**.
### 3) (Optional but good) Add your Google Pay merchant info
Stripe works without a separate Google merchant ID, but for production-grade branding:
– Create/verify a **Google Pay merchant ID** in the Google Pay & Wallet Console.
– In the Stripe/WCPay settings, add the merchant ID if the plugin exposes the field (improves trust labels in the sheet).
### 4) Place the button exactly where you want it
– With **Stripe plugin**, you can also drop the button anywhere:
<?php echo do_shortcode('[woocommerce_payment_request_button]'); ?>
– This renders a single **Google Pay / Pay button** when the browser & device are eligible.
### 5) Test it
– Use **Chrome** on Android with a saved card in Google Pay.
– Ensure you’re **not** inside an in-app browser (Facebook/Instagram often block it). Open in Chrome proper.
– Try Product page → Cart → Checkout to confirm appearance and flow.
### 6) Shipping, taxes, and totals
– Stripe’s Payment Request Button pulls **line items**, **shipping options**, and **tax** from WooCommerce automatically during the sheet flow.
– Keep your WooCommerce tax/shipping zones configured correctly so the Google Pay sheet shows valid options.
### 7) Go live checklist
– SSL lock showing ✅
– Country/currency supported ✅
– Button visible on at least Product & Cart ✅
– Test a full successful order in real Chrome/Android ✅
—
# Option B: Direct Google Pay API (custom)
Only use this if you **must** bypass Stripe/WCPay (e.g., your gateway is Adyen, Braintree, etc., or you have bespoke tokenization). You’ll need:
– A **Google Pay merchant ID**, domain verification, and a **gateway tokenization** config matching your PSP.
– A **custom plugin or theme code** to initialize the Google Pay JS API, map WooCommerce cart → Google Pay sheet, and create/process the order on return.
This is more engineering work and easy to get wrong; stick to Option A unless there’s a strong reason.
—
## Common issues & quick fixes
– **Button doesn’t show at all**
– Not on **Chrome/Android** with a saved card → it hides by design.
– You’re viewing inside **Facebook/Instagram in-app browser** → open in Chrome; in-app often blocks it.
– Currency/country not supported; or site not HTTPS.
– For Stripe: Payment Request Buttons disabled or not enabled on current page type.
– **Google Pay sheet opens but payment fails**
– Check gateway logs (**WooCommerce → Status → Logs**).
– Confirm your gateway account is **live vs test** consistently across client/server.
– Make sure totals, shipping methods, and taxes are valid on the current address.
– **Content Security Policy (CSP) blocks Google Pay**
– If you use CSP headers/meta, allow these at minimum:
script-src 'self' https://pay.google.com https://*.gstatic.com https://js.stripe.com;
frame-src 'self' https://pay.google.com https://*.gstatic.com https://js.stripe.com;
connect-src 'self' https://api.stripe.com https://r.stripe.com https://q.stripe.com;
– Don’t try to set `frame-ancestors` via “; set it via HTTP headers if needed.
– **Want a single “Buy with Google Pay” button (no Apple Pay)**
– Stripe auto-picks what’s available; on Android/Chrome you’ll see **Google Pay**.
– If you only want it on a specific page/section, use the **Stripe shortcode** above and leave other placements off.
—
If you tell me which plugin you’ve chosen (WooCommerce Payments vs Stripe), I’ll give you the exact clicks in your admin plus any code you need for your theme to place a **standalone Google Pay button** where you want it.
And they have google PayPal option but
It's come when we click PayPal radio button
I need some change i want to give separate radio button for google pay then it will come google pay button
Below are two practical ways to get what you want:
# 1) “Separate” Google Pay without changing gateway logic (quick + safe)
Show a **standalone Google Pay button** *outside* the PayPal radio using PayPal’s JS SDK “standalone buttons”. It behaves like its own option and doesn’t require selecting PayPal first.
High-level steps:
1) In **WooCommerce → Settings → Payments → PayPal**, keep PayPal enabled.
2) Add a container where you want the Google Pay button (e.g., above radios on checkout template).
3) Load the PayPal JS SDK with `components=googlepay` and render a **standalone** Google Pay button with `fundingSource: paypal.FUNDING.GOOGLEPAY`.
Why this works: PayPal’s SDK supports rendering **individual** methods as separate buttons (PayPal/Apple Pay/Google Pay/etc.) and only shows them when eligible. citeturn0search8turn0search20turn0search14
If you’re using **Blocks checkout**, you can also enable **Express buttons** (which include Google Pay) so the GPay button appears *separately* from the radio list. It’s “its own thing” visually and functionally. citeturn0search5
# 2) “Separate Google Pay” radio (UX hack that piggybacks PayPal)
If you really need a **radio line item** named “Google Pay”, you can add a tiny custom gateway that, when selected, auto-selects the PayPal gateway and filters the PayPal smart buttons to **only** show Google Pay. This keeps PayPal’s server flow, webhooks, and refunds intact.
**How it works**
– Register a dummy gateway `gpay_via_paypal` (no processing).
– On select, JS:
– Selects the PayPal method programmatically.
– Hides all PayPal buttons except Google Pay.
– Scrolls to the button.
This is lightweight and avoids re-implementing PayPal Orders API, but it’s a UI trick (not officially documented). If PayPal changes DOM/hooks, you may need to adjust selectors.
—
## Snippets (Option 2: radio hack)
**a) Add a minimal gateway (in a small plugin or your theme’s `functions.php`)**
add_filter('woocommerce_payment_gateways', function($methods){
$methods[] = 'WC_GPay_Via_PayPal';
return $methods;
});
add_action('plugins_loaded', function(){
class WC_GPay_Via_PayPal extends WC_Payment_Gateway {
public function __construct(){
$this->id = 'gpay_via_paypal';
$this->method_title = __('Google Pay (via PayPal)', 'yourtext');
$this->method_description = __('Pay quickly with Google Pay, processed by PayPal.', 'yourtext');
$this->has_fields = true;
$this->title = __('Google Pay', 'yourtext');
$this->enabled = 'yes';
}
public function payment_fields(){
echo '<p>' . esc_html__('Click the Google Pay button to complete your order.', 'yourtext') . '</p>';
echo '<div id="gpay-only-helper" style="display:none;"></div>';
}
public function process_payment($order_id){
// Never called because the PayPal button completes the payment.
return ['result' => 'fail'];
}
}
});
**b) Enqueue small JS to switch to PayPal + show only Google Pay**
add_action('wp_enqueue_scripts', function(){
if (is_checkout()) {
wp_add_inline_script('jquery-core', '
jQuery(function($){
const PAYPAL_METHOD_ID = "ppcp-gateway"; // PayPal Payments gateway id
function showOnlyGPay(){
// Select PayPal method
const $pp = $("#payment_method_" + PAYPAL_METHOD_ID);
if ($pp.length) { $pp.prop("checked", true).trigger("change"); }
// Hide other funding buttons, show only Google Pay
const container = document.querySelector("[data-ppcp-element="buttons"]") || document.querySelector("#paypal-button-container, .ppcp-button-container");
if (!container) return;
// PayPal uses data-funding-source on each rendered button
container.querySelectorAll("[data-funding-source]").forEach(el=>{
el.style.display = (el.getAttribute("data-funding-source") === "googlepay") ? "" : "none";
});
// Scroll to button
container.scrollIntoView({behavior:"smooth", block:"center"});
}
// When user selects our custom radio
$(document.body).on("change", "input[name=payment_method]", function(){
if (this.value === "gpay_via_paypal") {
// Give PayPal a tick to render if needed
setTimeout(showOnlyGPay, 200);
}
});
// If our method is preselected (refresh), enforce again
if ($("input#payment_method_gpay_via_paypal").is(":checked")) {
setTimeout(showOnlyGPay, 300);
}
});
');
}
});
> Notes:
> – The PayPal gateway ID is commonly `ppcp-gateway` for **WooCommerce PayPal Payments**. If yours differs, change `PAYPAL_METHOD_ID`.
> – The buttons container selector may vary by version/theme. Inspect and tweak `data-ppcp-element="buttons"` or `.ppcp-button-container` accordingly.
—
## CSP + environment reminders
If you run a Content Security Policy, allow these at minimum so Google Pay/PayPal can render:
script-src 'self' https://pay.google.com https://*.gstatic.com https://www.paypal.com;
frame-src 'self' https://pay.google.com https://*.gstatic.com https://www.paypal.com;
(If Stripe is also present, include `https://js.stripe.com` and its endpoints.) citeturn0search1turn0search4
—
## My recommendation for you
– **Fastest**: Enable **Blocks “Express Checkout”** so the Google Pay button appears on its own (no radio) – usually good enough UX. citeturn0search5
– **If you truly want a radio**: use the **Option 2** hack above. It keeps PayPal’s backend flow intact and only alters the UI.
If you’d like, tell me:
– Are you using **Classic checkout** or **Blocks checkout**?
– Your **PayPal Payments** plugin version.
– A checkout page URL (dev/staging).
I’ll tailor the exact selectors and provide a drop-in mini-plugin (zipped) for your setup.
Idea: we add a tiny “dummy” gateway called **Google Pay (via PayPal)**. When a shopper selects it, we automatically select the PayPal method and show **only** the Google Pay button. No checkout flow changes, refunds/webhooks still go through PayPal. It’s just cleaner UX.
—
# Drop-in mini-plugin (copy–paste)
Create a new file `wp-content/plugins/gpay-radio-via-paypal/gpay-radio-via-paypal.php` with this content:
<?php
/**
* Plugin Name: Google Pay – separate radio (via PayPal)
* Description: Adds a separate "Google Pay" payment method that piggybacks WooCommerce PayPal Payments and shows only the Google Pay button.
* Author: Your Team
* Version: 1.0.0
* Requires Plugins: woocommerce
*/
if (!defined('ABSPATH')) { exit; }
add_filter('woocommerce_payment_gateways', function($methods){
$methods[] = 'WC_GPay_Via_PayPal';
return $methods;
});
add_action('plugins_loaded', function(){
if (!class_exists('WC_Payment_Gateway')) return;
class WC_GPay_Via_PayPal extends WC_Payment_Gateway {
public function __construct(){
$this->id = 'gpay_via_paypal';
$this->icon = ''; // you can add a GPay SVG here
$this->method_title = __('Google Pay (via PayPal)', 'gpay-radio');
$this->method_description = __('Pay quickly with Google Pay. Processing is handled by PayPal.', 'gpay-radio');
$this->has_fields = true;
$this->title = __('Google Pay', 'gpay-radio');
$this->enabled = 'yes';
}
public function payment_fields(){
echo '<p>'.esc_html__('Click the Google Pay button to complete your order.', 'gpay-radio').'</p>';
// Marker to detect our method in JS
echo '<div id="gpay-only-helper" data-gpay-helper="1" style="display:none"></div>';
}
// Never actually processes; PayPal button will handle the order.
public function process_payment($order_id){
wc_add_notice(__('Please use the Google Pay button above to complete payment.', 'gpay-radio'), 'error');
return ['result' => 'failure'];
}
}
});
/**
* Front-end logic:
* - When our radio is picked, auto-select PayPal and render its buttons if needed.
* - Hide every PayPal funding button except Google Pay.
* - Scroll the shopper to the button.
*/
add_action('wp_enqueue_scripts', function(){
if (!function_exists('is_checkout') || !is_checkout()) return;
$code = <<<JS
jQuery(function($){
// Adjust if your PayPal gateway ID differs:
const PAYPAL_METHOD_ID = "ppcp-gateway"; // WooCommerce PayPal Payments (default)
// Potential containers where the PayPal buttons are rendered (Classic checkout).
const candidateSelectors = [
'[data-ppcp-element="buttons"]',
'.ppcp-button-container',
'#paypal-button-container',
'.wc-paypal-payments-buttons'
];
function findButtonsContainer(){
for (const sel of candidateSelectors){
const el = document.querySelector(sel);
if (el) return el;
}
// If not found yet, try inside the PayPal method wrapper
const ppWrap = document.getElementById('payment_method_' + PAYPAL_METHOD_ID)?.closest('li') || null;
if (ppWrap){
const el = ppWrap.querySelector('[data-ppcp-element="buttons"], .ppcp-button-container, #paypal-button-container, .wc-paypal-payments-buttons');
if (el) return el;
}
return null;
}
function showOnlyGooglePay(){
// Ensure PayPal method is selected so the plugin initializes its buttons
const $ppRadio = $("#payment_method_" + PAYPAL_METHOD_ID);
if ($ppRadio.length && !$ppRadio.is(":checked")){
$ppRadio.prop("checked", true).trigger("change");
}
// Wait a moment for buttons to render
let tries = 0;
const maxTries = 40; // ~4s
const t = setInterval(function(){
tries++;
const container = findButtonsContainer();
if (container){
// PayPal renders each button with a funding source attribute
const btns = container.querySelectorAll("[data-funding-source], [data-funding-source*='google']");
// Hide all buttons except Google Pay
container.querySelectorAll("[data-funding-source]").forEach(el => {
const fs = el.getAttribute("data-funding-source") || "";
el.style.display = (fs === "googlepay") ? "" : "none";
});
// If no Google Pay available, show a gentle notice
const hasGPay = container.querySelector("[data-funding-source='googlepay']");
if (!hasGPay){
// Make sure container is visible (in case PayPal delayed render)
// Add a small inline message for the user
let msg = container.querySelector(".gpay-eligibility-msg");
if (!msg){
msg = document.createElement('div');
msg.className = 'gpay-eligibility-msg';
msg.style.marginTop = '8px';
msg.style.fontSize = '13px';
msg.textContent = "Google Pay isn’t available on this device/browser.";
container.appendChild(msg);
}
}
// Bring into view
container.scrollIntoView({behavior: "smooth", block: "center"});
clearInterval(t);
} else if (tries >= maxTries){
clearInterval(t);
}
}, 100);
}
function onPaymentMethodChanged(){
const picked = $('input[name=payment_method]:checked').val();
if (picked === 'gpay_via_paypal'){
// Enforce our Google Pay-only view
showOnlyGooglePay();
}
}
// Bind change
$(document.body).on('change', 'input[name=payment_method]', onPaymentMethodChanged);
// Handle reloads where our method might be pre-selected
if ($('input#payment_method_gpay_via_paypal').is(':checked')){
showOnlyGooglePay();
}
// If the PayPal radio is selected later (user switches back), allow all buttons again
$(document.body).on('change', 'input#payment_method_' + PAYPAL_METHOD_ID, function(){
const container = findButtonsContainer();
if (!container) return;
container.querySelectorAll("[data-funding-source]").forEach(el => {
el.style.display = ""; // reset
});
const msg = container.querySelector(".gpay-eligibility-msg");
if (msg) msg.remove();
});
});
JS;
// Use jQuery core handle to inline our script after jQuery loads
wp_add_inline_script('jquery-core', $code);
});
Activate the plugin in **WP Admin → Plugins**.
—
## Notes / knobs you might tweak
– **Gateway ID**: For WooCommerce PayPal Payments the radio ID is usually `ppcp-gateway`. If yours differs, change `PAYPAL_METHOD_ID` in the script.
– **Container selectors**: The script looks for common PayPal buttons containers used by the plugin on **Classic checkout**. If your theme/markup differs, inspect the PayPal buttons container and add its selector to `candidateSelectors`.
– **CSP**: If you have a strict Content Security Policy, ensure it permits PayPal & Google Pay assets:
script-src 'self' https://www.paypal.com https://pay.google.com https://*.gstatic.com;
frame-src 'self' https://www.paypal.com https://pay.google.com https://*.gstatic.com;
– **Eligibility**: If the device/browser isn’t eligible for Google Pay, we show a small inline note (“Google Pay isn’t available on this device/browser.”).
—
## What you’ll see on checkout
– A new radio: **Google Pay**.
– Selecting it auto-selects the PayPal method, renders the PayPal smart buttons, and hides all funding options **except** Google Pay.
– Clicking the Google Pay button completes the order using the **existing PayPal gateway** (no backend changes).
If you share your checkout URL (staging) and the exact **WooCommerce PayPal Payments** version, I can tailor the container selector to your markup (so it’s 100% plug-and-play).