wc_get_product_id_by_sku()
Gets product ID by its SKU number.
The search is made by _sku
meta field among product
and product_variation
posts types.
No Hooks.
Return
Int
. Product ID or null if the product is not found.
Usage
wc_get_product_id_by_sku( $sku );
- $sku(string) (required)
- Product SKU.
Examples
#1 Get product ID
$sku = 'ta-15488ks'; $product_id = wc_get_product_id_by_sku( $sku );
Changelog
Since 2.3.0 | Introduced. |
wc_get_product_id_by_sku() wc get product id by sku code WC 9.6.1
function wc_get_product_id_by_sku( $sku ) { $data_store = WC_Data_Store::load( 'product' ); return $data_store->get_product_id_by_sku( $sku ); }