Как установить Woocommerce Shipping Total на программно созданный заказ - PullRequest
0 голосов
/ 17 октября 2019

Я использую эту функцию, чтобы создать новый заказ для своих клиентов ...

    public function create_order( $user_id, $address, $product_id ) {

        if ( ! $address ) return false;

        $address = array(
          'first_name' => $address->billing_first_name,
          'last_name'  => $address->billing_last_name,
          'email'      => $address->billing_email,
          'phone'      => $address->billing_phone,
          'address_1'  => $address->billing_address_1,
          'city'       => $address->billing_city,
          'state'      => $address->billing_state,
          'postcode'   => $address->billing_postcode,
          'country'    => $address->billing_country
        );

        $default_args = array(
            'status'        => 'wc-pending',
            'customer_id'   => $user_id,
        );

      // Now we create the order
      $order = wc_create_order( $default_args );

      $order->add_product( get_product( $product_id ), 1 ); // This is an existing SIMPLE product

      // set default address to the created order
      $order->set_address( $address, 'billing' );

      //calculate total order price
      $order->calculate_totals();

      $order->update_status( "pending", 'Order Created Successfully And Payment is not completed', TRUE );

      return $order;
}

Это создает новый заказ, но не рассчитывает стоимость доставки ... См. Скриншот ниже

Итоговая таблица созданного заказа

У меня фиксированная стоимость доставки, основанная на состоянии выставления счета пользователю и общем количестве товара .... так как мне автоматически настроить расчет доставки, как это происходитна кассе ..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...