WC_Data_Store::__construct()publicWC 1.0

Tells WC_Data_Store which object (coupon, product, order, etc) store we want to work with.

Метод класса: WC_Data_Store{}

Возвращает

null. Ничего (null).

Использование

$WC_Data_Store = new WC_Data_Store();
$WC_Data_Store->__construct( $object_type );
$object_type(строка) (обязательный)
Name of object.

Код WC_Data_Store::__construct() WC 8.7.0

public function __construct( $object_type ) {
	$this->object_type = $object_type;
	$this->stores      = apply_filters( 'woocommerce_data_stores', $this->stores );

	// If this object type can't be found, check to see if we can load one
	// level up (so if product-type isn't found, we try product).
	if ( ! array_key_exists( $object_type, $this->stores ) ) {
		$pieces      = explode( '-', $object_type );
		$object_type = $pieces[0];
	}

	if ( array_key_exists( $object_type, $this->stores ) ) {
		$store = apply_filters( 'woocommerce_' . $object_type . '_data_store', $this->stores[ $object_type ] );
		if ( is_object( $store ) ) {
			if ( ! $store instanceof WC_Object_Data_Store_Interface ) {
				throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
			}
			$this->current_class_name = get_class( $store );
			$this->instance           = $store;
		} else {
			if ( ! class_exists( $store ) ) {
				throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
			}
			$this->current_class_name = $store;
			$this->instance           = new $store();
		}
	} else {
		throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
	}
}