/**
  * Init billing and shipping fields we display + save
  */
 public static function init_address_fields()
 {
     self::$billing_fields = apply_filters('woocommerce_admin_billing_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false, 'class' => 'js_field-country select short', 'type' => 'select', 'options' => array('' => __('Select a country…', 'woocommerce')) + WC()->countries->get_allowed_countries()), 'state' => array('label' => __('State/County', 'woocommerce'), 'class' => 'js_field-state select short', 'show' => false), 'email' => array('label' => __('Email', 'woocommerce')), 'phone' => array('label' => __('Phone', 'woocommerce'))));
     self::$shipping_fields = apply_filters('woocommerce_admin_shipping_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false, 'type' => 'select', 'class' => 'js_field-country select short', 'options' => array('' => __('Select a country…', 'woocommerce')) + WC()->countries->get_shipping_countries()), 'state' => array('label' => __('State/County', 'woocommerce'), 'class' => 'js_field-state select short', 'show' => false)));
 }
Ejemplo n.º 2
0
 /**
  * Parent to Child synchronization
  *
  *
  * @param $parent_order_id  The parent id order
  * @param $parent_order     The parent order
  *
  * @internal param \WC_Order $parent_order
  *
  * @author   Andrea Grillo <*****@*****.**>
  * @since    1.6
  * @return void
  */
 public function suborder_meta_synchronization($parent_order_id, $parent_order)
 {
     //Check if order have sub-order
     if (wp_get_post_parent_id($parent_order_id)) {
         return false;
     }
     /** @var $suborder WC_Order */
     /** @var $parent_order WC_Order */
     $suborder_ids = self::get_suborder($parent_order_id);
     $parent_order = wc_get_order($parent_order_id);
     if (!empty($suborder_ids)) {
         foreach ($suborder_ids as $suborder_id) {
             $suborder = wc_get_order($suborder_id);
             $child_items = array_keys($suborder->get_items());
             $_post = $_POST;
             $_post['order_item_id'] = $child_items;
             $suborder_line_total = 0;
             foreach ($child_items as $child_items_id) {
                 $parent_item_id = $suborder->get_item_meta($child_items_id, '_parent_line_item_id');
                 $parent_item_id = absint(array_shift($parent_item_id));
                 foreach ($_post as $meta_key => $meta_value) {
                     //TODO: Shipping Cost
                     switch ($meta_key) {
                         case 'line_total':
                         case 'line_subtotal':
                         case 'order_item_tax_class':
                         case 'order_item_qty':
                         case 'refund_line_total':
                         case 'refund_order_item_qty':
                             if (isset($_post[$meta_key][$parent_item_id])) {
                                 $_post[$meta_key][$child_items_id] = $_post[$meta_key][$parent_item_id];
                                 unset($_post[$meta_key][$parent_item_id]);
                             }
                             break;
                         case 'shipping_cost':
                             if (isset($_post[$meta_key][$parent_item_id])) {
                                 $_post[$meta_key][$child_items_id] = 0;
                                 unset($_post[$meta_key][$parent_item_id]);
                             }
                             break;
                         default:
                             //nothing to do
                             break;
                     }
                 }
                 //Calculate Order Total
                 if (isset($_post['line_total'][$child_items_id])) {
                     $suborder_line_total += wc_format_decimal($_post['line_total'][$child_items_id]);
                 }
             }
             //New Order Total
             $_post['_order_total'] = wc_format_decimal($suborder_line_total);
             /**
              * Don't use save method by WC_Meta_Box_Order_Items class because I need to filter the POST information
              * use wc_save_order_items( $order_id, $items ) function directly.
              * @see WC_Meta_Box_Order_Items::save( $suborder_id, $suborder ); in woocommerce\includes\admin\meta-boxes\class-wc-meta-box-order-items.php:45
              * @see wc_save_order_items( $order_id, $items ); in woocommerce\includes\admin\wc-admin-functions.php:176
              */
             wc_save_order_items($suborder_id, $_post);
             WC_Meta_Box_Order_Downloads::save($suborder_id, $suborder);
             WC_Meta_Box_Order_Data::save($suborder_id, $suborder);
             WC_Meta_Box_Order_Actions::save($suborder_id, $suborder);
         }
     }
 }