From 56c427acba25c632a01d5a5a4ae0fc84d7ce96c1 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Tue, 24 Jan 2017 12:18:35 -0800 Subject: [PATCH 1/2] Add WC_Product_Data_Store_CPT::read_extra_data() So that a product's $extra_data can also be read by child classes of WC_Product_Data_Store_CPT, like WC_Product_Variation_Data_Store_CPT, without duplicating the code to read it. --- .../data-stores/class-wc-product-data-store-cpt.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 75091d5f709..24a16658508 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -136,6 +136,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da $this->read_downloads( $product ); $this->read_visibility( $product ); $this->read_product_data( $product ); + $this->read_extra_data( $product ); $product->set_object_read( true ); } @@ -260,9 +261,15 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da 'download_expiry' => get_post_meta( $id, '_download_expiry', true ), 'image_id' => get_post_thumbnail_id( $id ), ) ); + } - // Gets extra data associated with the product. - // Like button text or product URL for external products. + /** + * Read extra data associated with the product, like button text or product URL for external products. + * + * @param WC_Product + * @since 2.7.0 + */ + protected function read_extra_data( &$product ) { foreach ( $product->get_extra_data_keys() as $key ) { $function = 'set_' . $key; if ( is_callable( array( $product, $function ) ) ) { From f2cb083bd6b6646604d2f274c18d3ad745ac1f54 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Tue, 24 Jan 2017 12:20:15 -0800 Subject: [PATCH 2/2] Read extra data for variation products So that classes can extend WC_Product_Variation and use the existing WC_Product_Variation_Data_Store_CPT class, rather than having to create a new data store class to set the WC_Product_Variation::$extra_data values. --- .../data-stores/class-wc-product-variation-data-store-cpt.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index e70aa37797f..026e19f8d35 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -66,6 +66,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl ) ); $this->read_product_data( $product ); + $this->read_extra_data( $product ); $product->set_attributes( wc_get_product_variation_attributes( $product->get_id() ) ); // Set object_read true once all data is read.