I want to trigger action save_post_shop_order by url, because I have custom function that will create product meta there on checking.
I tried something like:
add_action('wp_head', 'update_orders_by_url');
function update_orders_by_url() {
if( isset( $_GET['update_woo_orders'] ) ) {
$query = new WC_Order_Query( array(
'limit' => -1
));
$orders = $query->get_orders();
foreach($orders as $order){
$arra2[] = $order;
// Save
$order->save();
}
}
//echo count($arra2);
}
But seems not working in my case.
How I can trigger update all orders and run action save_post_shop_order for all orders?
Thanks
2
Answers
You can do it this way, put your code in
functions.php
or aplugin
To update orders information through the URL, you can try the following steps.
On the top of the file, add this piece of code.
require(dirname(__FILE__) . '/wp-load.php');