Created
February 19, 2018 06:26
-
-
Save brycehamrick/c707af868d786a0948c1e4c4877e8212 to your computer and use it in GitHub Desktop.
Disable guest checkout if virtual products are in the cart.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' ); | |
function conditional_guest_checkout_based_on_product( $value ) { | |
if ( WC()->cart ) { | |
$cart = WC()->cart->get_cart(); | |
foreach ( $cart as $item ) { | |
$product = $item['data']; | |
if(!empty($product) && $product->is_virtual()){ | |
$value = "no"; | |
break; | |
} | |
} | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment