Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
How will you select certain products?
In a separate category or tag? Product type?
add_filter( 'woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1 );
function conditionally_remove_checkout_fields( $fields ) {
// Определяем категорию для которой отключем поля
$categories = array('house');
$found = false;
// Проверяем товары: находятся ли они в выше указаной категории?
foreach ( WC()->cart->get_cart() as $cart_item ){
if( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
$found = true;
break;
}
}
// Если товар принадлежит выше указаной категории, тогда отключаем поля
if ( $found ) {
// hide the billing fields
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_city']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_state']);
unset($fields['shipping']['shipping_phone']);
}
return $fields;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question