WordPress at a glance

wc_get_product_id_by_sku() WC 2.3.0

Gets product ID by its SKU number.

The search is made by _sku meta field among product and product_variation posts types.

No Hooks.


Int. Product ID or null if the product is not found.


wc_get_product_id_by_sku( $sku );
$sku(string) (required)
Product SKU.


#1 Get product ID

$sku = 'ta-15488ks';
$product_id = wc_get_product_id_by_sku( $sku );


Since 2.3.0 Introduced.

Code of wc get product id by sku: woocommerce/includes/wc-product-functions.php WC 4.2.2

function wc_get_product_id_by_sku( $sku ) {
	$data_store = WC_Data_Store::load( 'product' );
	return $data_store->get_product_id_by_sku( $sku );

Related Functions

From tag: sql

More from category: WooCommerce

vladlu 100vlad.lu
Editors: kama 100
No comments
        Log In . Register