'How to create woocommerce order from other wordpress site
I created a action hook on order created using woocommerce_checkout_create_order hook. But it returns internal server error with:
Uncaught Error: Call to a member function get_id() on null
Below is my code:
function passorder( $customer_id, $order_id ) {
$gogo_ck = 'ck_86b1d98af2e5afd483eeb12bb0df9c3da63b6eab';
$gogo_cs = 'cs_19c4c25423925809b1a2377b028fbf10d0eb50c6';
$live_url = 'https://gogopasar.vxstep.com/wp-json/wc/v3/orders?consumer_key=' . $gogo_ck . '&consumer_secret=' . $gogo_cs;
$customer = new WC_Customer( $customer_id );
$order_id = $order->get_id();
$order = new WC_Order($order_id);
$order_data= $order->get_data();
$body = array(
'status' => 'completed',
'meta_data' => array( array(
'key' => 'createdby',
'value' => 'luqmantest'
)),
'total' => 0,
'billing' => array(
'first_name' => $order_data->get_billing_first_name(),
'email' => $order_data->get_email(),
),
'line_items' => array( array(
'product_id' => 2995,
'quantity' => 1,
)),
);
$raw_response = wp_remote_post( $live_url,
array(
'headers' => array( 'Content-Type' => 'application/json' ),
'timeout' => 30,
'body' => json_encode( $body ),
)
);
}
What i want to achieve is when order is created, it will be created in other wordpress site also.
Using import and export is time-consuming.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
