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;
}
add_filter( 'woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1 );
function conditionally_remove_checkout_fields( $fields ) {
// Определяем категорию для которой отключем поля
$product_ids = array( 37, 53, 70 ); //перечень ID товаров для которых отключаем поля
$is_in_cart = false;
// Проверяем все товары
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $product_ids ) ){
$is_in_cart = true;
break;
}
// Если нашли, тогда выполняем....
if ( $is_in_cart ) {
// 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;
}
add_filter( 'woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1 );
function conditionally_remove_checkout_fields( $fields ) {
$set_one= array( 1, 2, 3); //перечень ID товаров для первого сета
$set_two= array( 4, 5, 6); //перечень ID товаров для второго сета
$set_three= array( 7, 8, 9); //перечень ID товаров для третьего сета
$is_in_cart = false;
// Проверяем первый сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_one) ){
$is_in_cart = true;
break;
}
if ( $is_in_cart ) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
// Проверяем второй сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_two) ){
$is_in_cart = true;
break;
}
if ( $is_in_cart ) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
// Проверяем трейтий сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_three) ){
$is_in_cart = true;
break;
}
if ( $is_in_cart ) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1 );
function conditionally_remove_checkout_fields( $fields ) {
$set_one= array( 1, 2, 3); //перечень ID товаров для первого сета
$set_two= array( 4, 5, 6); //перечень ID товаров для второго сета
$set_three= array( 7, 8, 9); //перечень ID товаров для третьего сета
$check_s1= false;
$check_s2= false;
$check_s3= false;
// Проверяем первый сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_one) ){
$check_s1= true;
break;
}
if ( $check_s1) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
// Проверяем второй сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_two) ){
$check_s2= true;
break;
}
if ( $check_s2) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
// Проверяем трейтий сет
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item )
if( in_array( $cart_item['data']->get_id(), $set_three) ){
$check_s3= true;
break;
}
if ( $check_s3) {
unset($fields['shipping']['shipping_first_name']);
}
return $fields;
}
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add select field to the checkout page
add_action('woocommerce_before_order_notes', 'wps_add_select_checkout_field');
function wps_add_select_checkout_field( $checkout ) {
echo '<h2>'.__('Next Day Delivery').'</h2>';
woocommerce_form_field( 'daypart', array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => __( 'Delivery options' ),
'options' => array(
'blank' => __( 'Select a day part', 'wps' ),
'morning' => __( 'In the morning', 'wps' ),
'afternoon' => __( 'In the afternoon', 'wps' ),
'evening' => __( 'In the evening', 'wps' )
)
),
$checkout->get_value( 'daypart' ));
}
add_filter( 'woocommerce_checkout_fields' , 'shipping_safe_checkout_fields' );
function shipping_safe_checkout_fields( $fields ) {
$fields['shipping']['shipping_daypart'] = array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => __( 'Delivery options' ),
'options' => array(
'blank' => __( 'Select a day part', 'wps' ),
'morning' => __( 'In the morning', 'wps' ),
'afternoon' => __( 'In the afternoon', 'wps' ),
'evening' => __( 'In the evening', 'wps' )
)
);
return $fields;
}
unset($fields['shipping']['shipping_daypart']);
if($name_surname !== '' && $name_surname !== NULL)
{
echo '<li><strong>Name and Surname:</strong> ' . $name_surname . '</li>';
};
add_action( 'woocommerce_email_order_meta', 'misha_add_email_order_meta', 10, 3 );
/*
* @param $order_obj Order Object
* @param $sent_to_admin If this email is for administrator or for a customer
* @param $plain_text HTML or Plain text (can be configured in WooCommerce > Settings > Emails)
*/
function misha_add_email_order_meta( $order_obj, $sent_to_admin, $plain_text ){
// this order meta checks if order is marked as a gift
$is_gift = get_post_meta( $order_obj->get_order_number(), 'is_gift', true );
// we won't display anything if it is not a gift
if( empty( $is_gift ) )
return;
// ok, if it is the gift order, get all the other fields
$gift_wrap = get_post_meta( $order_obj->get_order_number(), 'gift_wrap', true );
$gift_recipient = get_post_meta( $order_obj->get_order_number(), 'gift_name', true );
$gift_message = get_post_meta( $order_obj->get_order_number(), 'gift_message', true );
// ok, we will add the separate version for plaintext emails
if ( $plain_text === false ) {
// you shouldn't have to worry about inline styles, WooCommerce adds them itself depending on the theme you use
echo '<h2>Gift Information</h2>
<ul>
<li><strong>Is gift?</strong> Yes</li>
<li><strong>Gift Wrap:</strong> ' . $gift_wrap . '</li>
<li><strong>Recipient name:</strong> ' . $gift_recipient . '</li>
<li><strong>Gift message:</strong> ' . wpautop( $gift_message ) . '</li>
</ul>';
} else {
echo "GIFT INFORMATION\n
Is gift: Yes
Gift Wrap: $gift_wrap
Recipient name: $gift_recipient
Gift message: $gift_message";
}
}
// this order meta checks if order is marked as a gift
$is_gift = get_post_meta( $order_obj->get_order_number(), 'is_gift', true );
// we won't display anything if it is not a gift
if( empty( $is_gift ) )
return;
$gift_wrap = get_post_meta( $order_obj->get_order_number(), 'gift_wrap', true );
$lp_field = get_post_meta( $order_obj->get_order_number(), 'billing_lp', true );
if($name_surname !== '' && $name_surname !== NULL)
{
echo '<li><strong>Name and Surname:</strong> ' . $name_surname . '</li>';
};