WC_Product_Data_Store_CPT::get_product_id_by_global_unique_id()publicWC 9.1.0

Return product ID based on Unique ID.

Метод класса: WC_Product_Data_Store_CPT{}

Возвращает

int.

Использование

$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT();
$WC_Product_Data_Store_CPT->get_product_id_by_global_unique_id( $global_unique_id );
$global_unique_id(строка) (обязательный)
Product Unique ID.

Список изменений

С версии 9.1.0 Введена.

Код WC_Product_Data_Store_CPT::get_product_id_by_global_unique_id() WC 9.4.2

public function get_product_id_by_global_unique_id( $global_unique_id ) {
	global $wpdb;

	// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
	$id = $wpdb->get_var(
		$wpdb->prepare(
			"
			SELECT posts.ID
			FROM {$wpdb->posts} as posts
			INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
			WHERE
			posts.post_type IN ( 'product', 'product_variation' )
			AND posts.post_status != 'trash'
			AND lookup.global_unique_id = %s
			LIMIT 1
			",
			$global_unique_id
		)
	);
	/**
	 * Hook woocommerce_get_product_id_by_global_unique_id.
	 *
	 * @since 9.1.0
	 * @param mixed $id List of post statuses.
	 * @param string $global_unique_id Unique ID.
	 */
	return (int) apply_filters( 'woocommerce_get_product_id_by_global_unique_id', $id, $global_unique_id );
}