Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brycehamrick/c707af868d786a0948c1e4c4877e8212 to your computer and use it in GitHub Desktop.
Save brycehamrick/c707af868d786a0948c1e4c4877e8212 to your computer and use it in GitHub Desktop.
Disable guest checkout if virtual products are in the cart.
<?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