Merge pull request #16572 from woocommerce/fix/16559
Introduces woocommerce_get_product_id_by_sku filter
This commit is contained in:
commit
bdba4f7636
|
@ -846,12 +846,13 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
* Return product ID based on SKU.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param string $sku
|
||||
* @param string $sku Product SKU.
|
||||
* @return int
|
||||
*/
|
||||
public function get_product_id_by_sku( $sku ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_var( $wpdb->prepare( "
|
||||
|
||||
$id = $wpdb->get_var( $wpdb->prepare( "
|
||||
SELECT posts.ID
|
||||
FROM $wpdb->posts AS posts
|
||||
LEFT JOIN $wpdb->postmeta AS postmeta ON ( posts.ID = postmeta.post_id )
|
||||
|
@ -861,6 +862,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
AND postmeta.meta_value = '%s'
|
||||
LIMIT 1
|
||||
", $sku ) );
|
||||
|
||||
return (int) apply_filters( 'woocommerce_get_product_id_by_sku', $id, $sku );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -560,14 +560,12 @@ function wc_product_generate_unique_sku( $product_id, $sku, $index = 0 ) {
|
|||
* Get product ID by SKU.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @param string $sku
|
||||
* @param string $sku Product SKU.
|
||||
* @return int
|
||||
*/
|
||||
function wc_get_product_id_by_sku( $sku ) {
|
||||
$data_store = WC_Data_Store::load( 'product' );
|
||||
$product_id = $data_store->get_product_id_by_sku( $sku );
|
||||
|
||||
return ( $product_id ) ? intval( $product_id ) : 0;
|
||||
return $data_store->get_product_id_by_sku( $sku );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue