WC_Coupon_Data_Store_CPT::create()publicWC 3.0.0

Method to create a new coupon in the database.

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

Возвращает

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

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

$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT();
$WC_Coupon_Data_Store_CPT->create( $coupon );
$coupon(WC_Coupon) (обязательный) (передается по ссылке — &)
Coupon object.

Список изменений

С версии 3.0.0 Введена.

Код WC_Coupon_Data_Store_CPT::create() WC 8.7.0

public function create( &$coupon ) {
	if ( ! $coupon->get_date_created( 'edit' ) ) {
		$coupon->set_date_created( time() );
	}

	$coupon_id = wp_insert_post(
		apply_filters(
			'woocommerce_new_coupon_data',
			array(
				'post_type'     => 'shop_coupon',
				'post_status'   => 'publish',
				'post_author'   => get_current_user_id(),
				'post_title'    => $coupon->get_code( 'edit' ),
				'post_content'  => '',
				'post_excerpt'  => $coupon->get_description( 'edit' ),
				'post_date'     => gmdate( 'Y-m-d H:i:s', $coupon->get_date_created()->getOffsetTimestamp() ),
				'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $coupon->get_date_created()->getTimestamp() ),
			)
		),
		true
	);

	if ( $coupon_id ) {
		$coupon->set_id( $coupon_id );
		$this->update_post_meta( $coupon );
		$coupon->save_meta_data();
		$coupon->apply_changes();
		delete_transient( 'rest_api_coupons_type_count' );
		do_action( 'woocommerce_new_coupon', $coupon_id, $coupon );
	}
}