I would like to write a little script that does a check whenever an order is created in WooCommerce (right after checkout) and then conditionally changes the Shipping Address of the customer.
I think I need a filter hook that ‘fires’ as soon as an order is created. I tried several things in the WooCommerce Hook reference guide, like: ‘woocommerce_create_order’, but without success. I also contacted WooCommerce support, but no solution. I also checked out: Woocommerce hook after order (on Stackexchange), however I would need a filter hook that fires before order create (not after).
What I would like to accomplish is something like:
function alter_shipping ($order) {
if ($something == $condition) {
$order->shipping_address = "..."; //(simplified)
}
return $order;
}
add_filter( 'woocommerce_create_order', 'alter_shipping', 10, 1 );
This filter ‘woocommerce_create_order’ in above example doesn’t pass any variables to be manipulated.
I need to conditionally manipulate the shipping address in a WooCommerce order as it gets created. Does anyone know a suitable filter hook for this? Or another way?