WC_Coupon_Data_Store_CPT::get_ids_by_code( string $code )

Return an array of IDs for for a specific coupon code.


Description Description

Can return multiple to check for existence.


Parameters Parameters

$code

(Required) Coupon code.


Top ↑

Return Return

(array) Array of IDs.


Top ↑

Source Source

File: includes/data-stores/class-wc-coupon-data-store-cpt.php

	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",
				$code
			)
		);
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.