I need help to create a code.
I found this and im using this as main, but its not enough.
Require registration in WooCommerce for specific product
After the customer registers, they need to contact us before ordering.
After they have contacted us, we will upgrade their account to forexample as a subscriber.
Only subscribers can order the products ive listed as ID in the PHP.
- Customer creates an account, normal customer account.
- Customer add the product to cart, going to checkout —> “restricted” — must contact us before ordering.
- They contact us, we upgrade their account to forexample subscriber.
- Now they can buy the product.
I hope someone can help! 😀
Im using this at the moment, but its not enough for my requirements:
function filter_woocommerce_checkout_registration_required( $bool_value ) {
// Several can be added, separated by a comma
$product_ids = array ( 30, 813 );
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
// Product ID from cart item in specific array
if ( in_array( $cart_item['product_id'], $product_ids ) ) {
// Registration_required
$bool_value = true;
// Break loop
break;
}
}
return $bool_value;
}
add_filter( 'woocommerce_checkout_registration_required', 'filter_woocommerce_checkout_registration_required', 10, 1 );