使用WooCommerce API创建订单

时间:2019-05-24 13:27:21

标签: api woocommerce e-commerce angular7 woocommerce-rest-api

如何使用Woo-commerce API创建订单。 使用发布请求,我们如何使用Angular 7创建新订单

1 个答案:

答案 0 :(得分:0)

创建这样的对象以传递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);
        }
      );
  }