@@ 946-967 (lines=22) @@ | ||
943 | * @param string $sku Will be slashed to work around https://core.trac.wordpress.org/ticket/27421. |
|
944 | * @return bool |
|
945 | */ |
|
946 | public function is_existing_sku( $product_id, $sku ) { |
|
947 | global $wpdb; |
|
948 | ||
949 | // phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery |
|
950 | return $wpdb->get_var( |
|
951 | $wpdb->prepare( |
|
952 | " |
|
953 | SELECT posts.ID |
|
954 | FROM {$wpdb->posts} as posts |
|
955 | INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id |
|
956 | WHERE |
|
957 | posts.post_type IN ( 'product', 'product_variation' ) |
|
958 | AND posts.post_status != 'trash' |
|
959 | AND lookup.sku = %s |
|
960 | AND lookup.product_id <> %d |
|
961 | LIMIT 1 |
|
962 | ", |
|
963 | wp_slash( $sku ), |
|
964 | $product_id |
|
965 | ) |
|
966 | ); |
|
967 | } |
|
968 | ||
969 | /** |
|
970 | * Return product ID based on SKU. |
|
@@ 976-997 (lines=22) @@ | ||
973 | * @param string $sku Product SKU. |
|
974 | * @return int |
|
975 | */ |
|
976 | public function get_product_id_by_sku( $sku ) { |
|
977 | global $wpdb; |
|
978 | ||
979 | // phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery |
|
980 | $id = $wpdb->get_var( |
|
981 | $wpdb->prepare( |
|
982 | " |
|
983 | SELECT posts.ID |
|
984 | FROM {$wpdb->posts} as posts |
|
985 | INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id |
|
986 | WHERE |
|
987 | posts.post_type IN ( 'product', 'product_variation' ) |
|
988 | AND posts.post_status != 'trash' |
|
989 | AND lookup.sku = %s |
|
990 | LIMIT 1 |
|
991 | ", |
|
992 | $sku |
|
993 | ) |
|
994 | ); |
|
995 | ||
996 | return (int) apply_filters( 'woocommerce_get_product_id_by_sku', $id, $sku ); |
|
997 | } |
|
998 | ||
999 | /** |
|
1000 | * Returns an array of IDs of products that have sales starting soon. |