Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WC_Coupon_Data_Store_CPT::update_post_meta( WC_Coupon $coupon )
Helper method that updates all the post meta for a coupon based on it’s settings in the WC_Coupon class.
Description Description
Parameters Parameters
- $coupon
-
(Required) Coupon object.
Source Source
File: includes/data-stores/class-wc-coupon-data-store-cpt.php
private function update_post_meta( &$coupon ) { $meta_key_to_props = array( 'discount_type' => 'discount_type', 'coupon_amount' => 'amount', 'individual_use' => 'individual_use', 'product_ids' => 'product_ids', 'exclude_product_ids' => 'excluded_product_ids', 'usage_limit' => 'usage_limit', 'usage_limit_per_user' => 'usage_limit_per_user', 'limit_usage_to_x_items' => 'limit_usage_to_x_items', 'usage_count' => 'usage_count', 'date_expires' => 'date_expires', 'free_shipping' => 'free_shipping', 'product_categories' => 'product_categories', 'exclude_product_categories' => 'excluded_product_categories', 'exclude_sale_items' => 'exclude_sale_items', 'minimum_amount' => 'minimum_amount', 'maximum_amount' => 'maximum_amount', 'customer_email' => 'email_restrictions', ); $props_to_update = $this->get_props_to_update( $coupon, $meta_key_to_props ); foreach ( $props_to_update as $meta_key => $prop ) { $value = $coupon->{"get_$prop"}( 'edit' ); $value = is_string( $value ) ? wp_slash( $value ) : $value; switch ( $prop ) { case 'individual_use': case 'free_shipping': case 'exclude_sale_items': $value = wc_bool_to_string( $value ); break; case 'product_ids': case 'excluded_product_ids': $value = implode( ',', array_filter( array_map( 'intval', $value ) ) ); break; case 'product_categories': case 'excluded_product_categories': $value = array_filter( array_map( 'intval', $value ) ); break; case 'email_restrictions': $value = array_filter( array_map( 'sanitize_email', $value ) ); break; case 'date_expires': $value = $value ? $value->getTimestamp() : null; break; } $updated = $this->update_or_delete_post_meta( $coupon, $meta_key, $value ); if ( $updated ) { $this->updated_props[] = $prop; } } do_action( 'woocommerce_coupon_object_updated_props', $coupon, $this->updated_props ); }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |