Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::backfill_post_record
Backfills order details in to WP_Post DB. Uses WC_Order_Data_store_CPT.
Method of the class: OrdersTableDataStore{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$OrdersTableDataStore = new OrdersTableDataStore(); $OrdersTableDataStore->backfill_post_record( $order );
- $order(WC_Abstract_Order) (required)
- Order object to backfill.
OrdersTableDataStore::backfill_post_record() OrdersTableDataStore::backfill post record code WC 10.3.3
public function backfill_post_record( $order ) {
$cpt_data_store = $this->get_post_data_store_for_backfill();
if ( is_null( $cpt_data_store ) || ! method_exists( $cpt_data_store, 'update_order_from_object' ) ) {
return;
}
self::$backfilling_order_ids[] = $order->get_id();
// Attempt to create the backup post if missing.
if ( $order->get_id() && is_null( get_post( $order->get_id() ) ) ) {
if ( ! $this->maybe_create_backup_post( $order, 'backfill' ) ) {
// translators: %d is an order ID.
$this->error_logger->warning( sprintf( __( 'Unable to create backup post for order %d.', 'woocommerce' ), $order->get_id() ) );
return;
}
}
$this->update_order_meta_from_object( $order );
$order_class = get_class( $order );
$post_order = new $order_class();
$post_order->set_id( $order->get_id() );
if ( $cpt_data_store->order_exists( $order->get_id() ) ) {
$cpt_data_store->read( $post_order );
}
// This compares the order data to the post data and set changes array for props that are changed.
$post_order->set_props( $order->get_data() );
$cpt_data_store->update_order_from_object( $post_order );
foreach ( $cpt_data_store->get_internal_data_store_key_getters() as $key => $getter_name ) {
if (
is_callable( array( $cpt_data_store, "set_$getter_name" ) ) &&
is_callable( array( $this, "get_$getter_name" ) )
) {
call_user_func_array(
array(
$cpt_data_store,
"set_$getter_name",
),
array(
$order,
$this->{"get_$getter_name"}( $order ),
)
);
}
}
self::$backfilling_order_ids = array_diff( self::$backfilling_order_ids, array( $order->get_id() ) );
/**
* Fired when the backing post record for an HPOS order is backfilled after an order update.
*
* @since 8.5.0
*
* @param \WC_Order $order The order object.
*/
do_action( 'woocommerce_hpos_post_record_backfilled', $order );
}