godaddy-wordpress / wc-plugin-framework

The official SkyVerge WooCommerce plugin framework
Other
138 stars 42 forks source link

Apple Pay integration bypasses WooCommerce "Enable guest checkout" setting #359

Open sidedwards opened 4 years ago

sidedwards commented 4 years ago

I have guest checkout disabled in my WooCommerce settings.

Screen Shot 2019-11-21 at 6 21 05 PM

However, when I create orders through Apple Pay, it allows guest checkout.

Screen Shot 2019-11-21 at 6 33 08 PM

I noticed the WooCommerce Stripe gateway had the same issue a while back. https://github.com/woocommerce/woocommerce-gateway-stripe/issues/148

Is there any workaround to this?

ChaseWiseman commented 4 years ago

@sidedwards thanks for the report! We'll look at ways that can be improved for a future update.

In the meantime, you could use the sv_wc_apple_pay_is_available filter for determining Apple Pay availability that could be used to disable it in certain circumstances, like for guest users or users with certain permissions.

For instance, a snippet like this would do the trick:

function sv_wc_conditional_apple_pay( $is_available ) {

    if ( $is_available && ! get_current_user_id() && 'yes' !== get_option( 'woocommerce_enable_guest_checkout' ) ) {
        $is_available = false;
    }

    return $is_available;
}
add_filter( 'sv_wc_apple_pay_is_available', 'sv_wc_conditional_apple_pay' );