Answers for "how to search by sku woocommerce"

PHP
0

how to search by sku woocommerce

function get_product_by_sku( $sku ) {
  global $wpdb;

  $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );

  if ( $product_id ) return new WC_Product( $product_id );

  return null;
}
Posted by: Guest on January-22-2021

Code answers related to "how to search by sku woocommerce"

Browse Popular Code Answers by Language