WC_Data_Store::__construct
Tells WC_Data_Store which object (coupon, product, order, etc) store we want to work with.
Method of the class: WC_Data_Store{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Data_Store = new WC_Data_Store(); $WC_Data_Store->__construct( $object_type );
- $object_type(string) (required)
- Name of object.
WC_Data_Store::__construct() WC Data Store:: construct code WC 10.6.2
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' ) );
}
}