added method to stop save duplicate sku in quick edit
This commit is contained in:
parent
4afeb7926c
commit
eb54adf697
|
@ -742,12 +742,36 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
|
|||
* Quick edit
|
||||
*/
|
||||
private function quick_edit_save( $post_id, $product ) {
|
||||
global $wpdb;
|
||||
|
||||
$old_regular_price = $product->regular_price;
|
||||
$old_sale_price = $product->sale_price;
|
||||
|
||||
// Save fields
|
||||
if ( isset( $_REQUEST['_sku'] ) ) update_post_meta( $post_id, '_sku', wc_clean( $_REQUEST['_sku'] ) );
|
||||
if ( isset( $_REQUEST['_sku'] ) ) {
|
||||
$sku = get_post_meta( $post_id, '_sku', true );
|
||||
$new_sku = wc_clean( stripslashes( $_REQUEST['_sku'] ) );
|
||||
|
||||
if ( $new_sku !== $sku ) {
|
||||
if ( ! empty( $new_sku ) ) {
|
||||
$sku_exists = $wpdb->get_var( $wpdb->prepare("
|
||||
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'
|
||||
", $new_sku ) );
|
||||
|
||||
if ( ! $sku_exists ) {
|
||||
update_post_meta( $post_id, '_sku', $new_sku );
|
||||
}
|
||||
} else {
|
||||
update_post_meta( $post_id, '_sku', '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['_weight'] ) ) update_post_meta( $post_id, '_weight', wc_clean( $_REQUEST['_weight'] ) );
|
||||
if ( isset( $_REQUEST['_length'] ) ) update_post_meta( $post_id, '_length', wc_clean( $_REQUEST['_length'] ) );
|
||||
if ( isset( $_REQUEST['_width'] ) ) update_post_meta( $post_id, '_width', wc_clean( $_REQUEST['_width'] ) );
|
||||
|
|
Loading…
Reference in New Issue