Posted on

Custom min bid increase based on current bid value

Is there a possibility to have minimal bid increments based on current bid amount? Yes, and you can use this code snippet in your child theme functions.php or via Code Snippets plugin.

function afw_bid_value_classes( $metadata, $object_id, $meta_key, $single ) {

	if ( isset( $meta_key ) && '_auction_bid_increment' === $meta_key ) {

		$product = wc_get_product( $object_id );

		if( (! $product) || $product->get_type() != 'auction' ){
			return $metadata;
		}

		$bid_value = $product->get_curent_bid();

			switch ( $bid_value ) {
				case $bid_value <= 25:
					$auction_bid_increment = 1;
					break;
				case ( $bid_value > 25 && $bid_value <= 80 ):
					$auction_bid_increment = 5;
					break;
				case ( $bid_value > 80 && $bid_value <= 230 ):
					$auction_bid_increment = 10;
					break;
				case ( $bid_value > 230 && $bid_value <= 750 ):
					$auction_bid_increment = 20;
					break;
				case ( $bid_value > 750 ):
					$auction_bid_increment = 100;
					break;
			}

		return $auction_bid_increment;
	}
	// Return original if the check does not pass
	return $metadata;
}

add_filter( 'get_post_metadata', 'afw_bid_value_classes', 100, 4 );

Increase bid by percentage:

add_filter( 'auctions_for_woocommerce_bid_value', 'afw_auctions_bid_value_percentage', 10, 2 );
 add_filter( 'auctions_for_woocommerce_proxy_bid_value', 'afw_auctions_bid_value_percentage', 10, 2 );

function afw_auctions_bid_value_percentage ( $bid_value, $product ){
    
    $auction_bid_increment = ($product->get_auction_bid_increment()) ?(float)$product->get_curent_bid() * ((float)$product->get_auction_bid_increment()/100) : 1;
 
    if( (int)$product->get_auction_bid_count() == '0' ){

            return $product->get_curent_bid();
        
		} else  {
        
			if($product->get_auction_type() == 'reverse' ){
                return round( wc_format_decimal($product->get_curent_bid()) - wc_format_decimal($auction_bid_increment),wc_get_price_decimals());
            }else{
                return round(  wc_format_decimal($product->get_curent_bid()) + wc_format_decimal($auction_bid_increment),wc_get_price_decimals());
            }
        }
}