Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //* Add select field to the checkout page
- add_action('woocommerce_before_order_notes', 'barbareshet_add_select_checkout_field');
- function barbareshet_add_select_checkout_field( $checkout ) {
- $current_user = wp_get_current_user();
- if ( !user_can( $current_user, 'administrator')) return;
- woocommerce_form_field( 'order_method', array(
- 'type' => 'radio',
- 'class' => array( 'barbareshet-drop' ),
- 'label' => __( 'Order Method', 'oceanwp-child' ),
- 'options' => array(
- 'online' => __( 'online', 'oceanwp-child' ),
- 'phone' => __( 'by phone', 'oceanwp-child' ),
- )
- ),
- $checkout->get_value( 'order_method' ));
- }
- // save custom field values
- function barbareshet_save_order_cf( $order_id ){
- if( !empty( $_POST['order_method'] ) )
- update_post_meta( $order_id, 'order_method', sanitize_text_field( $_POST['order_method'] ) );
- }
- // save fields to order meta
- add_action( 'woocommerce_checkout_update_order_meta', 'barbareshet_save_order_cf' );
- function barbareshet_checkout_field_display_admin_order_meta($order){
- echo '<p><strong>'.__('Order Method', 'oceanwp-child').':</strong> <br/>' . get_post_meta( $order->get_id(), 'order_method', true ) . '</p>';
- }
- add_action( 'woocommerce_admin_order_data_after_billing_address', 'barbareshet_checkout_field_display_admin_order_meta', 10, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement