Add filter woocommerce_update_product_stock_query

This commit is contained in:
Frédéric Demarle 2019-02-05 20:29:45 +01:00
parent b2542d7e8c
commit 6e4854b3aa
1 changed files with 17 additions and 21 deletions

View File

@ -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' );
}