xxxxxxxxxx
add_action( 'woocommerce_checkout_order_created', 'my_hooked_function_callback', 10 );
function my_hooked_function_callback( $order ) {
$url = "https://example.com/do_something";
$data = wp_remote_post( $url, array(
'headers' => array(
'Authorization' => "Token my_token",
'Content-Type' => 'application/json; charset=utf-8',
),
'body' => json_encode( array(
'order_id' => $order->get_id()
) ),
'method' => 'POST',
'data_format' => 'body',
) );
}
xxxxxxxxxx
<?php
/**
* Plugin Name: MyPlugin
*/
function my_hook($order_id) {
$url = "https://example.com/do_something";
$data = wp_remote_post($url, array(
'headers' => array(
'Authorization' => "Token my_token",
'Content-Type' => 'application/json; charset=utf-8',
),
'body' => json_encode(array('order_id' => $order_id)),
'method' => 'POST',
'data_format' => 'body',
));
}
add_action(
'woocommerce_new_order',
'my_hook'
);
?>