From 9b7a4b2273c963e0b6f9571fd3ba1b6bc3d42b2e Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Fri, 26 Apr 2024 15:21:21 -0500 Subject: [PATCH 1/2] [#925] Disable ReserveStock and Bid Variation Backorders --- .../goodbids/src/classes/Auctions/Auction.php | 4 -- .../goodbids/src/classes/Auctions/Bids.php | 2 +- .../goodbids/src/classes/Auctions/Cron.php | 3 -- .../src/classes/Plugins/WooCommerce.php | 38 +++++++++++++++++++ .../Emails/AuctionIsEndingSoon.php | 1 - 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/Auctions/Auction.php b/client-mu-plugins/goodbids/src/classes/Auctions/Auction.php index 0e7c4252b..10a0b4f41 100644 --- a/client-mu-plugins/goodbids/src/classes/Auctions/Auction.php +++ b/client-mu-plugins/goodbids/src/classes/Auctions/Auction.php @@ -1444,10 +1444,6 @@ public function increase_bid(): bool { if ( $bid_variation ) { $current_price = floatval( $bid_variation->get_price( 'edit' ) ); - - // Disallow backorders on previous variation. - $bid_variation->set_backorders( 'no' ); - $bid_variation->save(); } else { $current_price = $this->get_last_bid_value(); } diff --git a/client-mu-plugins/goodbids/src/classes/Auctions/Bids.php b/client-mu-plugins/goodbids/src/classes/Auctions/Bids.php index a6b808533..67b2d9484 100644 --- a/client-mu-plugins/goodbids/src/classes/Auctions/Bids.php +++ b/client-mu-plugins/goodbids/src/classes/Auctions/Bids.php @@ -363,7 +363,7 @@ public function create_new_bid_variation( int $bid_product_id, float $bid_price, // Stock Management, Somewhat locked down. $variation->set_manage_stock( true ); $variation->set_stock_quantity( 1 ); - $variation->set_backorders( 'yes' ); // This resolves a cart conflict. + $variation->set_backorders( 'no' ); $variation->set_sold_individually( true ); $variation->set_virtual( true ); diff --git a/client-mu-plugins/goodbids/src/classes/Auctions/Cron.php b/client-mu-plugins/goodbids/src/classes/Auctions/Cron.php index d4b5d5bf8..24f303867 100644 --- a/client-mu-plugins/goodbids/src/classes/Auctions/Cron.php +++ b/client-mu-plugins/goodbids/src/classes/Auctions/Cron.php @@ -219,12 +219,9 @@ private function schedule_auction_ending_soon_check(): void { 'init', function (): void { if ( wp_next_scheduled( Auctions::CRON_AUCTION_ENDING_SOON_CHECK_HOOK ) ) { - Log::debug( 'Auction Ending Soon Cron Check already scheduled' ); return; } - Log::debug( 'Scheduling Auction Ending Soon Cron Check' ); - // Event is not scheduled, so schedule it. wp_schedule_event( strtotime( current_time( 'mysql' ) ), diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php index 6d767b2dc..c98e08387 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php @@ -144,6 +144,9 @@ public function __construct() { $this->redirect_after_login(); $this->redirect_after_registration(); + // Disable WooCommerce ReserveStock functionality. + $this->disable_reserve_stock(); + // Adjust Out of Stock Error to reflect Duplicate Bids. $this->adjust_out_of_stock_error(); @@ -454,6 +457,41 @@ function ( $redirect ) { ); } + /** + * Disable WooCommerce ReserveStock functionality. + * + * @since 1.0.1 + * + * @return void + */ + private function disable_reserve_stock(): void { + add_filter( + 'query', + function ( string $query ): string { + global $wpdb; + if ( ! str_contains( $query, $wpdb->wc_reserved_stock ) || ! str_contains( $query, 'INSERT INTO' ) ) { + return $query; + } + + return 'SELECT 1'; + }, + 10, + 2 + ); + + remove_action( 'woocommerce_checkout_order_created', 'wc_reserve_stock_for_order' ); + + add_filter( + 'woocommerce_hold_stock_for_checkout', + fn () => 'no' + ); + + add_filter( + 'option_woocommerce_hold_stock_minutes', + fn () => 0 + ); + } + /** * Empty Cart and Modify Error when out of stock error is received. * diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionIsEndingSoon.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionIsEndingSoon.php index 8347d5982..2c4027315 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionIsEndingSoon.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionIsEndingSoon.php @@ -57,7 +57,6 @@ public function __construct() { * @return void */ private function cron_check_for_auctions_ending_soon(): void { - Log::debug( 'Init: Check for Auctions Ending Soon' ); add_action( Auctions::CRON_AUCTION_ENDING_SOON_CHECK_HOOK, function (): void { From 5bca5f3d921732fdb81b691df7128afce5f0d2bc Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Mon, 29 Apr 2024 08:03:35 -0500 Subject: [PATCH 2/2] [#925] Remove unnecessary parameters --- .../goodbids/src/classes/Plugins/WooCommerce.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php index c98e08387..48d395beb 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php @@ -474,9 +474,7 @@ function ( string $query ): string { } return 'SELECT 1'; - }, - 10, - 2 + } ); remove_action( 'woocommerce_checkout_order_created', 'wc_reserve_stock_for_order' );