Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #4538209
Cheapest field in product grid
Open

Comments

  •  1
    David started the conversation

    Hi, is there any way or code snippet I can use to display the lowest price configured for that product on the shop page (on each product card) using the WPC Price by Quantity plugin?

  •  1,618
    Dustin replied

    Hi David,

    Please add the custom code below. (How to add custom code? ↗):

    add_filter( 'woocommerce_get_price_html', function ( $price_html, $product ) {
    	if ( ! class_exists( 'Wpcpq_Helper' ) ) {
    		return $price_html;
    	}
    
    	if ( is_a( $product, 'WC_Product' ) ) {
    		$product_id = $product->get_id();
    	} else {
    		$product_id = absint( $product );
    		$product    = wc_get_product( $product_id );
    	}
    
    	if ( Wpcpq_Helper()::is_enable( $product_id ) ) {
    		$pricing = Wpcpq_Helper()::get_pricing( $product_id );
    
    		if ( ! empty( $pricing['tiers'] ) && is_array( $pricing['tiers'] ) ) {
    			if ( $price = $product->get_price() ) {
    				$last_tier  = end( $pricing['tiers'] );
    				$last_price = Wpcpq_Helper()::get_price( $pricing['method'], $pricing['tiers'], $last_tier['quantity'], $price );
    
    				return 'From: ' . wc_price( $last_price );
    			}
    		}
    	}
    
    	return $price_html;
    }, 999, 2 );

    Best regards,
    Dustin