Files
woocommerce-subscriptions/includes/data-stores/class-wcs-product-variable-data-store-cpt.php
Prospress Inc 3ff3a8b701 2.4.7
2018-12-24 09:06:01 +01:00

50 lines
1.6 KiB
PHP
Executable File

<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WCS Variable Product Data Store: Stored in CPT.
*
* @version 2.3.0
* @author Prospress
*/
class WCS_Product_Variable_Data_Store_CPT extends WC_Product_Variable_Data_Store_CPT {
/**
* A cache of products having their min and max variation data read.
* Used as a circuit breaker to prevent multiple object reads causing infinite loops.
*
* @var array
*/
protected static $reading_min_max_variation_data = array();
/**
* Method to read a product from the database.
*
* @param WC_Product_Variable_Subscription $product Product object.
* @throws Exception If invalid product.
*/
public function read( &$product ) {
parent::read( $product );
$this->read_min_max_variation_data( $product );
}
/**
* Read min and max variation data from post meta.
*
* @param WC_Product_Variable_Subscription $product Product object.
*/
protected function read_min_max_variation_data( &$product ) {
if ( ! isset( self::$reading_min_max_variation_data[ $product->get_id() ] ) && ! $product->meta_exists( '_min_max_variation_ids_hash' ) ) {
self::$reading_min_max_variation_data[ $product->get_id() ] = '';
$product->set_min_and_max_variation_data();
update_post_meta( $product->get_id(), '_min_max_variation_data', $product->get_meta( '_min_max_variation_data', true ), true );
update_post_meta( $product->get_id(), '_min_max_variation_ids_hash', $product->get_meta( '_min_max_variation_ids_hash', true ), true );
unset( self::$reading_min_max_variation_data[ $product->get_id() ] );
}
}
}