Replace the example ID with an order that contains representative data. The guard keeps the existing preview data when the order cannot be loaded.
Developer note:
Add custom PHP in a small custom plugin or child theme, and test it on a staging site before production. This example requires ongoing maintenance when extension APIs change.
functions.php
<?php
add_filter( 'automatewoo/preview_data_layer', 'my_store_automatewoo_preview_order' );
/**
* Set the order and customer used in workflow previews.
*
* @param array $data Preview data.
* @return array
*/
function my_store_automatewoo_preview_order( $data ) {
$order = wc_get_order( 123 );
if ( ! $order ) {
return $data;
}
$customer = AutomateWoo\Customer_Factory::get_by_order( $order );
if ( ! $customer ) {
return $data;
}
$data['order'] = $order;
$data['customer'] = $customer;
return $data;
}