我正在使用一种产品的woocommerce会员资格,其余的woocommerce产品是一般产品。
但我希望访问者能够注册woocommerce会员资格,但不能注册其他产品。对于其他产品,我想使用客人结账。
你可以使用GitHub上的solution。
// Code goes in theme functions.php or a custom plugin
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' );
function conditional_guest_checkout_based_on_product( $value ) {
$restrict_ids = array( 1, 2, 3 ); // Replace with product ids which cannot use guest checkout
if ( WC()->cart ) {
$cart = WC()->cart->get_cart();
foreach ( $cart as $item ) {
if ( in_array( $item['product_id'], $restrict_ids ) ) {
$value = "no";
break;
}
}
}
return $value;
}