WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::get_product_id_by_sku() public WC 3.0.0

Return product ID based on SKU.

{} It's a method of the class: WC_Product_Data_Store_CPT{}

Hooks from the method
Return

Int.

Usage

$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT();
$WC_Product_Data_Store_CPT->get_product_id_by_sku( $sku );
$sku(string) (required)
Product SKU.

Changelog

Since 3.0.0 Introduced.

Code of WC_Product_Data_Store_CPT::get_product_id_by_sku() WC 5.6.0

public function get_product_id_by_sku( $sku ) {
	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.sku = %s
			LIMIT 1
			",
			$sku
		)
	);

	return (int) apply_filters( 'woocommerce_get_product_id_by_sku', $id, $sku );
}