P
P
Pavel2017-02-05 09:20:34
WordPress
Pavel, 2017-02-05 09:20:34

Send idorder after checkout to external server?

Try to do it like this:
add_action( 'woocommerce_create_order', 'so_woocommerce_create_order' );
function so_woocommerce_create_order( $order_id ){
$order = wc_get_order( $order_id );
$url = ' site.ru/savehook.php ';
wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' = > array(),
'body' => array('order'=>$order),
'cookies' => array()
)
);
}
But the data is not returned to me.
Did I choose the right action? I tried both the name of the hook for adding an order, and using actions from the api, but maybe I'm wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-02-23
@neon51r

Solved through hooks.
The only thing that needed to be done was to process it.
$_POST = json_decode(file_get_contents('php://input'), true);
$id= $_POST['order']['id'],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question