SKU exists check
This commit is contained in:
parent
d58e3d7877
commit
95c8669431
|
@ -472,8 +472,18 @@ function woocommerce_process_product_meta( $post_id, $post ) {
|
||||||
if ($new_sku!==$sku) :
|
if ($new_sku!==$sku) :
|
||||||
if ($new_sku && !empty($new_sku)) :
|
if ($new_sku && !empty($new_sku)) :
|
||||||
if (
|
if (
|
||||||
$wpdb->get_var($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s';", $new_sku)) ||
|
$wpdb->get_var($wpdb->prepare("
|
||||||
$wpdb->get_var($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID='%s' AND ID!='%s' AND post_type='product';", $new_sku, $post_id))
|
SELECT $wpdb->posts.ID
|
||||||
|
FROM $wpdb->posts
|
||||||
|
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
|
||||||
|
WHERE $wpdb->posts.post_type = 'product'
|
||||||
|
AND $wpdb->posts.post_status = 'publish'
|
||||||
|
AND (
|
||||||
|
($wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s')
|
||||||
|
OR
|
||||||
|
($wpdb->posts.ID = '%s' AND $wpdb->posts.ID != '%s')
|
||||||
|
);
|
||||||
|
", $new_sku, $new_sku, $post_id))
|
||||||
) :
|
) :
|
||||||
$woocommerce_errors[] = __('Product SKU must be unique.', 'woocommerce');
|
$woocommerce_errors[] = __('Product SKU must be unique.', 'woocommerce');
|
||||||
else :
|
else :
|
||||||
|
|
Loading…
Reference in New Issue