×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Rockstar Madhav
Added: Jul 12, 2014 7:37 PM
Modified: Jul 12, 2014 7:39 PM
Views: 35
  1. add_filter( 'woocommerce_shipping_fields' , 'my_custom_shipping_fields' );
  2. function my_custom_shipping_fields( $fields ) {
  3.  
  4.      $fields['shipping_address_type'] = array(
  5.                 'type'              =>  'text',
  6.                 'label'         => __('Address Type', 'woocommerce'),
  7.                 'placeholder' => _x('Address Type', 'placeholder', 'woocommerce'),
  8.                 'required'      => true,
  9.                 'class'         => array('form-row'),
  10.                 'clear'         => true,
  11.                 'options'     => array(
  12.                         'select' => __('Select...', 'woocommerce' ),
  13.                 'House' => __('House', 'woocommerce' ),
  14.                 'Multi-Unit' => __('Apartment or Condo', 'woocommerce' ),
  15.                 'Business' => __('Business', 'woocommerce' )
  16.                     )
  17.                 );
  18.  
  19.      return $fields;
  20. }
  21.  
  22. add_action( 'woocommerce_checkout_process', 'my_custom_checkout_field_process');
  23. function my_custom_checkout_field_process() {
  24.  
  25.     if ($_POST['address_type'] == "text")
  26.     {
  27.     wc_add_notice( __( 'Please tell us the Address Type we are delivering to.' ), 'error' );
  28.     }
  29. }
  30.  
  31. add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
  32.         function my_custom_checkout_field_update_order_meta( $order_id ) {
  33.  
  34.             if ( ! empty( $_POST['shipping_address_type'] ) ) {
  35.                 update_post_meta( $order_id, 'Address Type', esc_attr( $_POST[ 'shipping_address_type' ]) );
  36.             }
  37.         }
  38.                 add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1 );
  39. function my_custom_fields_display_admin_order_meta( $order ) {
  40.     echo '<p><strong>'.__('Address Type').':</strong> ' . get_post_meta( $order->id, 'Address Type', true ) . '</p>';
  41. }