WC_Coupon_Data_Store_CPT::get_code_by_id()publicWC 3.0.0

Return a coupon code for a specific ID.

Method of the class: WC_Coupon_Data_Store_CPT{}

No Hooks.

Return

String. Coupon Code

Usage

$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT();
$WC_Coupon_Data_Store_CPT->get_code_by_id( $id );
$id(int) (required)
Coupon ID.

Changelog

Since 3.0.0 Introduced.

WC_Coupon_Data_Store_CPT::get_code_by_id() code WC 8.7.0

public function get_code_by_id( $id ) {
	global $wpdb;
	return $wpdb->get_var(
		$wpdb->prepare(
			"SELECT post_title
			FROM $wpdb->posts
			WHERE ID = %d
			AND post_type = 'shop_coupon'
			AND post_status = 'publish'",
			$id
		)
	);
}