I have created the following plugin, which is supposed to send a POST HTTP request to an external server when a Woocommerce order is created. However, this is not happening: no request received on the external server, nothing is showing up in wp-content/debug.log
(I do have define( 'WP_DEBUG_LOG', true );
in wp-config.php
). What am I doing wrong?
<?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'
);
?>