WC_Product_Data_Store_CPT::get_product_id_by_global_unique_id()
Return product ID based on Unique ID.
Method of the class: WC_Product_Data_Store_CPT{}
Hooks from the method
Return
Int
.
Usage
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->get_product_id_by_global_unique_id( $global_unique_id );
- $global_unique_id(string) (required)
- Product Unique ID.
Changelog
Since 9.1.0 | Introduced. |
WC_Product_Data_Store_CPT::get_product_id_by_global_unique_id() WC Product Data Store CPT::get product id by global unique id code WC 9.4.2
public function get_product_id_by_global_unique_id( $global_unique_id ) { global $wpdb; // phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery $id = $wpdb->get_var( $wpdb->prepare( " SELECT posts.ID FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id WHERE posts.post_type IN ( 'product', 'product_variation' ) AND posts.post_status != 'trash' AND lookup.global_unique_id = %s LIMIT 1 ", $global_unique_id ) ); /** * Hook woocommerce_get_product_id_by_global_unique_id. * * @since 9.1.0 * @param mixed $id List of post statuses. * @param string $global_unique_id Unique ID. */ return (int) apply_filters( 'woocommerce_get_product_id_by_global_unique_id', $id, $global_unique_id ); }