WC_Coupon_Data_Store_CPT::get_coupon_meta_as_array()
Get a metadata value that is stored as either a string consisting of a comma-separated list of values or as a serialized array.
WooCommerce always stores the coupon product ids as a comma-separated string, but it seems that some plugins mistakenly change these to an array.
Method of the class: WC_Coupon_Data_Store_CPT{}
No Hooks.
Return
Array
. The metadata value as an array, with empty values removed.
Usage
// private - for code of main (parent) class only $result = $this->get_coupon_meta_as_array( $coupon_id, $meta_key );
- $coupon_id(int) (required)
- The coupon id.
- $meta_key(string) (required)
- The meta key to get.
WC_Coupon_Data_Store_CPT::get_coupon_meta_as_array() WC Coupon Data Store CPT::get coupon meta as array code WC 9.4.2
private function get_coupon_meta_as_array( $coupon_id, string $meta_key ) { $meta_value = get_post_meta( $coupon_id, $meta_key, true ); return array_filter( is_array( $meta_value ) ? $meta_value : explode( ',', $meta_value ) ); }