在 Ionic 4 中使用 WooCommerce API v3 创建订单

Create an order using WooCommerce API v3 in Ionic 4

我正在使用 Angular v7Ionic v4

如何使用 Woo-commerce API 创建订单?
WooCommerce v3
WC版本3.5.x
WordPress 版本 4.4
离子 v4
Angular v7

使用 post 请求我们如何使用 WooCommmerceAngular 7 & [ 中创建新订单=15=]离子4 提交订单后清空购物车

像这样创建一个对象以传入POST方法

createOrderData = {
    payment_method: "cod",
    payment_method_title: "Cash on delivery",
    set_paid: true,
    billing: {
      first_name: "John",
      last_name: "Doe",
      address_1: "969 Market",
      address_2: "",
      city: "San Francisco",
      state: "CA",
      postcode: "57000",
      country: "PK",
      email: "john.doe@example.com",
      phone: "(555) 555-5555"
    },
    shipping: {
      first_name: "John",
      last_name: "Doe",
      address_1: "969 Market",
      address_2: "",
      city: "San Francisco",
      state: "CA",
      postcode: "57000",
      country: "Pk"
    },
    line_items: [
      {
        product_id: 7191,
        quantity: 2
      },
      {
        product_id: 7195,
        variation_id: 23,
        quantity: 1
      }
    ]
  }

然后创建一个函数&调用这个函数来执行post方法

addOrder() {
    this.http.post("https://www.websitename.com/wp-json/wc/v3/orders?consumer_key=ck_xxxxxxxxxxxxxxxxxxxxx&consumer_secret=cs_xxxxxxxxxxxxxxxxxxxxx", this.createOrderData)
      .subscribe(
        async data => {
          console.log("Order successfully created", data);
        },
        async error => {
          console.log("Error", error);
        }
      );
  }