Skip to content
This repository was archived by the owner on Jun 15, 2022. It is now read-only.

Commit 74bb51e

Browse files
committed
Clean up the code for the data stores' read_order_data() methods
1 parent 8852ebd commit 74bb51e

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

includes/class-wc-order-data-store-custom-table.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,29 @@ public function delete( &$order, $args = array() ) {
4747
}
4848

4949
/**
50-
* Read order data.
50+
* Read order data from the custom orders table.
5151
*
52-
* @param WC_Order $order The order object, passed by reference.
52+
* If the order does not yet exist, the plugin will attempt to migrate it automatically. This
53+
* behavior can be modified via the "wc_custom_order_table_automatic_migration" filter.
54+
*
55+
* @param WC_Order $order The order object, passed by reference.
5356
* @param object $post_object The post object.
5457
*/
5558
protected function read_order_data( &$order, $post_object ) {
56-
global $wpdb;
57-
5859
$data = $this->get_order_data_from_table( $order );
5960

6061
if ( ! empty( $data ) ) {
6162
$order->set_props( $data );
62-
6363
} else {
64-
// Automatically backfill order data from meta, but allow for disabling.
65-
if ( apply_filters( 'wc_custom_order_table_automatic_migration', true ) ) {
64+
/**
65+
* Toggle the ability for WooCommerce Custom Orders Table to automatically migrate orders.
66+
*
67+
* @param bool $migrate Whether or not orders should automatically be migrated once they
68+
* have been loaded.
69+
*/
70+
$migrate = apply_filters( 'wc_custom_order_table_automatic_migration', true );
71+
72+
if ( $migrate ) {
6673
$this->populate_from_meta( $order );
6774
}
6875
}

includes/class-wc-order-refund-data-store-custom-table.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@
1515
class WC_Order_Refund_Data_Store_Custom_Table extends WC_Order_Refund_Data_Store_CPT {
1616

1717
/**
18-
* Read refund data.
18+
* Read refund data from the custom orders table.
1919
*
20-
* @param WC_Order_Refund $refund The refund object, passed by reference.
21-
* @param object $post_object The post object.
20+
* If the refund does not yet exist, the plugin will attempt to migrate it automatically. This
21+
* behavior can be modified via the "wc_custom_order_table_automatic_migration" filter.
22+
*
23+
* @param WC_Refund $order The refund object, passed by reference.
24+
* @param object $post_object The post object.
2225
*/
23-
protected function read_order_data( &$refund, $post_object ) {
24-
global $wpdb;
25-
26-
$data = $this->get_order_data_from_table( $refund );
26+
protected function read_order_data( &$order, $post_object ) {
27+
$data = $this->get_order_data_from_table( $order );
2728

2829
if ( ! empty( $data ) ) {
29-
$refund->set_props( $data );
30-
30+
$order->set_props( $data );
3131
} else {
32-
// Automatically backfill refund data from meta, but allow for disabling.
33-
if ( apply_filters( 'wc_custom_order_table_automatic_migration', true ) ) {
34-
$this->populate_from_meta( $refund );
32+
/** This filter is defined in class-wc-order-data-store-custom-table.php. */
33+
$migrate = apply_filters( 'wc_custom_order_table_automatic_migration', true );
34+
35+
if ( $migrate ) {
36+
$this->populate_from_meta( $order );
3537
}
3638
}
3739
}

0 commit comments

Comments
 (0)