WC_Coupon::__construct() public WC 1.0
Coupon constructor. Loads coupon data.
{} Это метод класса: WC_Coupon{}
Хуки из метода
Возвращает
Null. Ничего.
Использование
$WC_Coupon = new WC_Coupon(); $WC_Coupon->__construct( $data );
- $data(разное)
- Coupon data, object, ID or code.
Код WC_Coupon::__construct() WC Coupon:: construct WC 5.0.0
public function __construct( $data = '' ) {
parent::__construct( $data );
// If we already have a coupon object, read it again.
if ( $data instanceof WC_Coupon ) {
$this->set_id( absint( $data->get_id() ) );
$this->read_object_from_database();
return;
}
// This filter allows custom coupon objects to be created on the fly.
$coupon = apply_filters( 'woocommerce_get_shop_coupon_data', false, $data, $this );
if ( $coupon ) {
$this->read_manual_coupon( $data, $coupon );
return;
}
// Try to load coupon using ID or code.
if ( is_int( $data ) && 'shop_coupon' === get_post_type( $data ) ) {
$this->set_id( $data );
} elseif ( ! empty( $data ) ) {
$id = wc_get_coupon_id_by_code( $data );
// Need to support numeric strings for backwards compatibility.
if ( ! $id && 'shop_coupon' === get_post_type( $data ) ) {
$this->set_id( $data );
} else {
$this->set_id( $id );
$this->set_code( $data );
}
} else {
$this->set_object_read( true );
}
$this->read_object_from_database();
}