WC_Product_Data_Store_CPT::is_existing_global_unique_id()
Check if product sku is found for any other product IDs.
Method of the class: WC_Product_Data_Store_CPT{}
No Hooks.
Return
true|false
.
Usage
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->is_existing_global_unique_id( $product_id, $global_unique_id );
- $product_id(int) (required)
- Product ID.
- $global_unique_id(string) (required)
- Will be slashed to work around https://core.trac.wordpress.org/ticket/27421.
Changelog
Since 9.1.0 | Introduced. |
WC_Product_Data_Store_CPT::is_existing_global_unique_id() WC Product Data Store CPT::is existing global unique id code WC 9.4.2
public function is_existing_global_unique_id( $product_id, $global_unique_id ) { global $wpdb; // phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery return (bool) $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 AND lookup.product_id <> %d LIMIT 1 ", wp_slash( $global_unique_id ), $product_id ) ); }