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.

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 );

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

<?php
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

No comments
    Hello, !     Log In . Register