Product Icon

Square for WooCommerce

Trending
Woo's preferred POS partner, Square, makes online and in-person payments seamless with transparent rates, fast deposits, and integrated inventory management.

Disable Apple Pay and Google Pay if cart contains any virtual product

Apple Pay and Google Pay can really mess with virtual product access. It would be nice to have a toggle in settings to automate this feature. For now I have added this to my functions.php in my child theme (and it works) but would be nice for it to be a supported function:

/**
* Hide Apple Pay and Google Pay buttons (provided by Square) if the cart contains any virtual products.
*/
add_filter( ‘wc_square_display_digital_wallet_on_pages’, ‘custom_hide_square_digital_wallets_for_virtual_products’ );

function custom_hide_square_digital_wallets_for_virtual_products( $pages ) {
// Check if the cart is initialized and not empty
if ( WC()->cart && ! WC()->cart->is_empty() ) {
$has_virtual_products = false;

// Loop through cart products
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item[‘data’]; // Get the WC_Product object

// Check if the product (or its variation) is virtual
if ( $product->is_virtual() ) {
$has_virtual_products = true;
break; // No need to check further if one virtual product is found
}
}

// If any virtual products are in the cart, remove ‘cart’ and ‘checkout’ from the pages array
if ( $has_virtual_products ) {
$pages = array_diff( $pages, array( ‘cart’, ‘checkout’ ) );
}
}

return $pages;
}

Author

jessicastudentmidwifestudygramcouk

Current Status

Open

Last updated: June 7, 2025

0 comments

Log in to comment on this feature request.