WC_Meta_Box_Coupon_Data::save()public staticWC 1.0

Save meta box data.

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

Хуки из метода

Возвращает

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

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

$result = WC_Meta_Box_Coupon_Data::save( $post_id, $post );
$post_id(int) (обязательный)
-
$post(WP_Post) (обязательный)
-

Код WC_Meta_Box_Coupon_Data::save() WC 8.7.0

public static function save( $post_id, $post ) {
	// Check for dupe coupons.
	$coupon_code  = wc_format_coupon_code( $post->post_title );
	$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $post_id );

	if ( $id_from_code ) {
		WC_Admin_Meta_Boxes::add_error( __( 'Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce' ) );
	}

	$product_categories         = isset( $_POST['product_categories'] ) ? (array) $_POST['product_categories'] : array();
	$exclude_product_categories = isset( $_POST['exclude_product_categories'] ) ? (array) $_POST['exclude_product_categories'] : array();

	$coupon = new WC_Coupon( $post_id );
	$coupon->set_props(
		array(
			'code'                        => $post->post_title,
			'discount_type'               => wc_clean( $_POST['discount_type'] ),
			'amount'                      => wc_format_decimal( $_POST['coupon_amount'] ),
			'date_expires'                => wc_clean( $_POST['expiry_date'] ),
			'individual_use'              => isset( $_POST['individual_use'] ),
			'product_ids'                 => isset( $_POST['product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) : array(),
			'excluded_product_ids'        => isset( $_POST['exclude_product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) : array(),
			'usage_limit'                 => absint( $_POST['usage_limit'] ),
			'usage_limit_per_user'        => absint( $_POST['usage_limit_per_user'] ),
			'limit_usage_to_x_items'      => absint( $_POST['limit_usage_to_x_items'] ),
			'free_shipping'               => isset( $_POST['free_shipping'] ),
			'product_categories'          => array_filter( array_map( 'intval', $product_categories ) ),
			'excluded_product_categories' => array_filter( array_map( 'intval', $exclude_product_categories ) ),
			'exclude_sale_items'          => isset( $_POST['exclude_sale_items'] ),
			'minimum_amount'              => wc_format_decimal( $_POST['minimum_amount'] ),
			'maximum_amount'              => wc_format_decimal( $_POST['maximum_amount'] ),
			'email_restrictions'          => array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ),
		)
	);
	$coupon->save();
	do_action( 'woocommerce_coupon_options_save', $post_id, $coupon );
}