Add filter woocommerce_update_product_stock_query
This commit is contained in:
parent
b2542d7e8c
commit
6e4854b3aa
|
@ -1235,37 +1235,33 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
// Update stock in DB directly.
|
||||
switch ( $operation ) {
|
||||
case 'increase':
|
||||
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = meta_value + %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
)
|
||||
$sql = $wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = meta_value + %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
);
|
||||
break;
|
||||
case 'decrease':
|
||||
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = meta_value - %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
)
|
||||
$sql = $wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = meta_value - %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
)
|
||||
$sql = $wpdb->prepare(
|
||||
"UPDATE {$wpdb->postmeta} SET meta_value = %f WHERE post_id = %d AND meta_key='_stock'",
|
||||
$stock_quantity,
|
||||
$product_id_with_stock
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$sql = apply_filters( 'woocommerce_update_product_stock_query', $sql, $product_id_with_stock, $stock_quantity, $operation );
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->query( $sql );
|
||||
|
||||
wp_cache_delete( $product_id_with_stock, 'post_meta' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue