Guest User

Disable Variable Product Price Range

a guest
Apr 19th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /*Disable Variable Product Price Range*/
  2.  
  3. add_filter( 'woocommerce_variable_sale_price_html', 'my_variation_price_format', 10, 2 );
  4.  
  5. add_filter( 'woocommerce_variable_price_html', 'my_variation_price_format', 10, 2 );
  6.  
  7. function my_variation_price_format( $price, $product ) {
  8.  
  9. // Main Price
  10. $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
  11. $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
  12.  
  13. // Sale Price
  14. $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
  15. sort( $prices );
  16. $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
  17.  
  18. if ( $price !== $saleprice ) {
  19. $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
  20. }
  21. return $price;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment