[Enhancement] Create new filter `wc_lock_sku_query` for SKU lock query. (#49755)

Create a new filter wc_lock_sku_query to allow third party to filter the SKU lock query.

Fixes #49660

* Create new filter wc_lock_sku_query.

* Bail early with filter prop @coreymckrill

Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Hugo Drelon 2024-08-09 01:15:20 +02:00 committed by GitHub
parent b01aabef29
commit 47e4d918c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Add a filter to override the SKU database lock.

View File

@ -131,6 +131,20 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
$sku,
$sku
);
/**
* Filter to bail early on the SKU lock query.
*
* @since 9.3.0
*
* @param bool|null $locked Set to a boolean value to short-circuit the SKU lock query.
* @param WC_Product $product The product being created.
*/
$locked = apply_filters( 'wc_product_pre_lock_on_sku', null, $product );
if ( ! is_null( $locked ) ) {
return boolval( $locked );
}
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$result = $wpdb->query( $query );