Skip to content

Commit

Permalink
[#925] Disable ReserveStock and Bid Variation Backorders (#932)
Browse files Browse the repository at this point in the history
* [#925] Disable ReserveStock and Bid Variation Backorders

* [#925] Remove unnecessary parameters
  • Loading branch information
bd-viget authored Apr 29, 2024
1 parent 1b90fdf commit ffe89b1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
4 changes: 0 additions & 4 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion client-mu-plugins/goodbids/src/classes/Auctions/Bids.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
3 changes: 0 additions & 3 deletions client-mu-plugins/goodbids/src/classes/Auctions/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ),
Expand Down
36 changes: 36 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -454,6 +457,39 @@ 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';
}
);

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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ffe89b1

Please sign in to comment.