Z
Z
zeaovede2021-12-31 12:10:00
WooCommerce
zeaovede, 2021-12-31 12:10:00

How to pass options to woo email template?

I found an article with the output of fields in non-standard WC groups.
Checked the code, it works

// Добавляем поле Детали оплаты
add_filter( 'woocommerce_checkout_fields' , 'billing_safe_checkout_fields' );

function billing_safe_checkout_fields( $fields ) {
  
    $fields['billing']['billing_whatsapp'] = array(
    'type'          => 'checkbox',   
    'required'    => false,
    'class'       => array('form-row-wide'),
    'clear'       => true,
    'label'       => 'Сообщить о заказе на whatsapp',
    'options' => array(
      '1' => 'whatsapp',
    )
     );

     return $fields;
}



// Сохраняем метаданные заказа со значениями полей
add_action( 'woocommerce_checkout_update_order_meta', 'custom_field_checkout_update_order_meta' );
function custom_field_checkout_update_order_meta( $order_id ) {

  if ( ! empty( $_POST['billing_whatsapp'] ) ) { 
    update_post_meta( $order_id, 'billing_whatsapp', 'yes' );
  }

}


// Добавляем полей в админку
add_action( 'woocommerce_admin_order_data_after_billing_address', 'custom_field_display_admin_order_meta', 10, 1 );
function custom_field_display_admin_order_meta($order){
  
  if(get_post_meta( $order->get_id(), 'billing_whatsapp', true )) { 
  echo '<p><strong>Отправить заказ на Whatsapp</strong></p>';
  }

}


// Вывод полей на странице заказа
add_action( 'woocommerce_order_details_after_order_table', 'custom_field_display_order_page', 10, 1 );
function custom_field_display_order_page($order){
  
  if(get_post_meta( $order->get_id(), 'billing_whatsapp', true )) { 
    echo '<p><strong>Отправить заказ на Whatsapp</strong></p><br>';
  }	

}



// Добавить поля в шаблон письма
function cloudways_show_email_order_meta( $order, $sent_to_admin, $plain_text ) {
    if(get_post_meta( $order->get_id(), 'billing_whatsapp', true )) { 
        echo '<p style="margin: 0 0 16px;"><strong>Отправить заказ на Whatsapp</strong></p>';
    }

}
add_action('woocommerce_email_order_meta', 'cloudways_show_email_order_meta', 20, 3 );


Hence the question. In the example, only one option is displayed for selection. But specifically in my case there will be several options to choose from. How to pass all options to an email template, but only the selected option is displayed in the email itself?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question