Home / eCommerce / Remove Express Checkout Button for Wholesale Users
Duplicate Snippet

Embed Snippet on Your Site

Remove Express Checkout Button for Wholesale Users

Removes the Apple Pay and Google Pay buttons for Wholesale Users

Code Preview
php
<?php
#== Remove Express Checkout Button for Wholesale Users ==#
function remove_express_checkout_button() {
    global $wp_filter, $wc_wholesale_prices;
    $user_wholesale_role = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole();
    if( empty( $user_wholesale_role ) ) {
        return;
    }
    
    $hooks_to_clean = [
        'woocommerce_after_add_to_cart_form' => 1,
        'woocommerce_proceed_to_checkout' => 21,
        'woocommerce_checkout_before_customer_details' => 1,
        'woocommerce_pay_order_before_payment' => 1,
    ];
    
    foreach ( $hooks_to_clean as $hook => $priority ) {
        if ( isset( $wp_filter[$hook] ) && isset( $wp_filter[$hook]->callbacks[$priority] ) ) {
            foreach ( $wp_filter[$hook]->callbacks[$priority] as $key => $callback ) {
                if ( is_array( $callback['function'] ) && 
                     is_object( $callback['function'][0] ) && 
                     get_class( $callback['function'][0] ) === 'WC_Payments_Express_Checkout_Button_Display_Handler' &&
                     $callback['function'][1] === 'display_express_checkout_buttons' ) {
                    unset( $wp_filter[$hook]->callbacks[$priority][$key] );
                }
            }
        }
    }
}
add_action( 'init', 'remove_express_checkout_button' );

Comments

Add a Comment