Created
September 24, 2014 15:52
-
-
Save dannyconnolly/c5066e86991151711d7b to your computer and use it in GitHub Desktop.
How to Find Product by SKU in WooCommerce - http://www.skyverge.com/blog/find-product-sku-woocommerce/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment