wc_get_product_id_by_sku

Get product ID by SKU.

Description

(int) wc_get_product_id_by_sku( (string) $sku ); 

Returns (int)

Parameters (1)

0. $sku (string)
The sku.

Usage

  1. if ( !function_exists( 'wc_get_product_id_by_sku' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4. // The sku. 
  5. $sku = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_product_id_by_sku($sku); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-product-functions.php  
  1. function wc_get_product_id_by_sku( $sku ) { 
  2. global $wpdb; 
  3.  
  4. $data_store = WC_Data_Store::load( 'product' ); 
  5. $product_id = $data_store->get_product_id_by_sku( $sku ); 
  6.  
  7. return ( $product_id ) ? intval( $product_id ) : 0;