WC_Coupon_Data_Store_CPT::get_ids_by_code()publicWC 3.0.0

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.

Return

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() code WC 9.4.2

public function get_ids_by_code( $code ) {
	global $wpdb;
	return $wpdb->get_col(
		$wpdb->prepare(
			"SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' ORDER BY post_date DESC",
			wc_sanitize_coupon_code( $code )
		)
	);
}