WC_Coupon_Data_Store_CPT::get_ids_by_code
Return an array of IDs for for a specific coupon code. Can return multiple to check for existence.
Method of the class: WC_Coupon_Data_Store_CPT{}
No Hooks.
Returns
Array. Array of IDs.
Usage
$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT(); $WC_Coupon_Data_Store_CPT->get_ids_by_code( $code );
- $code(string) (required)
- Coupon code.
Changelog
| Since 3.0.0 | Introduced. |
WC_Coupon_Data_Store_CPT::get_ids_by_code() WC Coupon Data Store CPT::get ids by code code WC 10.3.3
public function get_ids_by_code( $code ) {
global $wpdb;
return $wpdb->get_col(
$wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE LOWER(post_title) = LOWER(%s) AND post_type = 'shop_coupon' AND post_status = 'publish' ORDER BY post_date DESC",
wc_sanitize_coupon_code( $code )
)
);
}