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 );