• Resolved screamson

    (@screamson)


    Hello.
    I have a lot of variable products on my site. They are all made with the help of the functional variability of woocommerce.
    Each variation of the product has the same price. Which varies depending on the quantity of the product with your plugin.
    How do I show the minimum price of the product with the prefix “from”?
    I. e. here is the settings page https://drive.google.com/file/d/1EtefilcYKnlzVN9A_cSyt9UvROniZBdN/view?usp=drivesdk. I need to instead of the standard price of the goods shown “From 500 to 800 rubles,” or “From 500 rubles.”
    How can I achieve this?
    P.S.: I’m from Russia, so my English can be bad. I’m sorry about that.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author algol.plus

    (@algolplus)

    hello

    could you try this code ?
    thanks, Alex

    add_filter( 'woocommerce_get_price_html', function ( $price ) {
    	global $woocommerce, $product;
    
    	if( empty( $product) OR empty(WC()->customer) ) 
    		return $price; 
    
    	$rules = WDP_Frontend::get_active_rules_for_product($product->get_id(), $qty = 50);
    	if( $rules ) {
    		$bulk = $rules[0]->get_bulk_details();
    		$range = array_pop($bulk['ranges']);
    		$price = 'From ' . wc_price( wc_get_price_to_display( $product, array( 'price' => $range['value'] ) ) ) ;
    	}
    	return $price;
    }, 10, 2);
    Thread Starter screamson

    (@screamson)

    Thanks for the quick response!
    It worked! Put the filter in, cleaned the cache and it worked.
    Thank you very much for your help!
    I think it would be super to add the option to display the price type (minimum/maximum/range/bulk) in the plugin functionality.
    Thanks again for the quick help, your plugin is the best!

    • This reply was modified 5 years, 7 months ago by screamson. Reason: I was wrong with the first answer, everything worked
    Plugin Author algol.plus

    (@algolplus)

    Hi

    Unfortunately, we can’t add new settings to UI – it will work for simple use cases only and might confuse users.

    If you setup 2 rules ( “fixed cost” bulk for category and “fixed discount” bulk for role) for the category, what price should we show ?
    We can’t just use values from tables.

    So provided code works only if you have ONE rule for the product.

    thanks, Alex

    • This reply was modified 5 years, 7 months ago by algol.plus.

    Hi, I have a problem using this snippet. It changes the “from price” to products that don’t have rules on it too. Can ite be fixed? Thanks.

    Plugin Author algol.plus

    (@algolplus)

    here is updated version

    add_filter( 'woocommerce_get_price_html', function ( $price ) {
    	global $woocommerce, $product;
    
    	if( empty( $product) OR empty(WC()->customer) ) 
    		return $price; 
    
    	$rules = WDP_Frontend::get_active_rules_for_product($product->get_id(), $qty = 50, $use_empty_cart = true);
    	if( $rules ) {
    		$context  = WDP_Frontend::make_wdp_cart_context_from_wc();
    		$bulk = $rules[0]->get_bulk_details($context);
    		if( $bulk  ) {
    			$range = array_pop($bulk['ranges']);
    			$price = 'From ' . wc_price( wc_get_price_to_display( $product, array( 'price' => $range['value'] ) ) ) ;
    		}	
    	}
    	return $price;
    }, 10, 2);
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘show minimal bulk price’ is closed to new replies.