📜  如何通过 sku woocommerce 进行搜索 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:37.350000             🧑  作者: Mango

代码示例1
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;
}