2017-11-04 76 views
0

我在我的第一個WooCommerce自定義字段上非常接近。我的問題似乎是將自定義字段的輸入數據發佈到「訂單詳細信息」頁面上。WooCommerce將自定義字段數據發佈到訂單詳細信息頁面問題

對於似乎我的生活,我不能用這個代碼來查找問題:

   // Register main datepicker jQuery plugin script 
      add_action('wp_enqueue_scripts', 'enabling_date_picker'); 
      function enabling_date_picker() { 

       // Only on front-end and checkout page 
       if(is_admin() || ! is_checkout()) return; 

       // Load the datepicker jQuery-ui plugin script 
       wp_enqueue_script('jquery-ui-datepicker'); 
      } 

      // Call datepicker functionality in your custom text field 
      add_action('woocommerce_after_order_notes', 'my_custom_checkout_field', 10, 1); 
      function my_custom_checkout_field($checkout) { 

       date_default_timezone_set('America/Los_Angeles'); 
       $mydateoptions = array('' => __('Select PickupDate', 'woocommerce')); 

       echo '<div id="my_custom_checkout_field"> 
       <h3>'.__('Empty Cylinder Collection').'</h3>'; 

       // YOUR SCRIPT HERE BELOW 
       echo ' 
       <script> 
        jQuery(function($){ 
         $("#datepicker").datepicker(); 
        }); 
       </script>'; 

       woocommerce_form_field('cylinder_collect_date', array(
        'type'   => 'text', 
        'class'   => array('my-field-class form-row-wide'), 
        'id'   => 'datepicker', 
        'required'  => false, 
        'label'   => __('Collection Date'), 
        'placeholder'  => __('Select Date'), 
        'options'  => $mydateoptions 
        ),$checkout->get_value('cylinder_collect_date')); 

       echo '</div>'; 
      } 
      /** 
      * Process the checkout 
      **/ 
      add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); 

      function my_custom_checkout_field_process() { 
       global $woocommerce; 

       // Check if set, if its not set add an error. 
       if (!$_POST['cylinder_collect_date']) 
        wc_add_notice('<strong>Collection Date</strong> ' . __('is a required field.', 'woocommerce'), 'error'); 
      } 

      /** 
      * Update the order meta with custom fields values 
      * */ 
      add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); 

      function my_custom_checkout_field_update_order_meta($order_id) { 

      if (!empty($_POST['cylinder_collect_date'])) { 
       update_post_meta($order_id, 'Pick-up Empty Cylinder', sanitize_text_field($_POST['cylinder_collect_date'])); 
      } 
      } 

      /** 
      * Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders 
      * */ 
      add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); 

      function my_custom_fields_display_admin_order_meta($order) { 
      echo "<h4>Empty Cylinder Collection</h4>"; 
      echo '<p><strong>' . __('Collection Date') . ':</strong><br> ' . get_post_meta($order->id, 'cylinder_collect_date', true) . '</p>'; 

      } 

      /** 
      * Display Custom Billing fields in the Order details area in Woocommerce->orders 
       * */ 
      add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); 

      function my_custom_billing_fields_display_admin_order_meta($order) { 
      echo "<h4>Empty Cylinder Collection</h4>"; 
      echo '<p><strong>' . __('Collection Date') . ':</strong><br> ' . get_post_meta($order->id, 'cylinder_collect_date', true) . '</p>'; 
      } 

我使用Flatsome主題,我將此代碼添加到主題的INC文件

參考:https://stage.helium2go.com.au

任何援助將不勝感激

回答

0

我已用下面的代碼固定它

/** 
* Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders 
* */ 
add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); 

function my_custom_fields_display_admin_order_meta($order) { 
echo "<h4>Empty Cylinder Collection</h4>"; 
echo '<p><strong>' . __('Collection Date') . ':</strong><br> ' . get_post_meta($order->id, 'Pick-up Empty Cylinder', true) . '</p>'; 

} 

/** 
* Display Custom Billing fields in the Order details area in Woocommerce->orders 
    * */ 
add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); 

function my_custom_billing_fields_display_admin_order_meta($order) { 
echo "<h4>Empty Cylinder Collection</h4>"; 
echo '<p><strong>' . __('Collection Date') . ':</strong><br> ' . get_post_meta($order->id, 'Pick-up Empty Cylinder', true) . '</p>'; 
} 

我需要使用:提取空氣缸

相關問題