Advertisement
meetsos

Variable Product Price Range Remove only Larger Value

Jan 12th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter( 'woocommerce_variable_sale_price_html', 'my_variation_price_format', 10, 2 );
  4. add_filter( 'woocommerce_variable_price_html', 'my_variation_price_format', 10, 2 );
  5.  
  6. function my_variation_price_format( $price, $product ) {
  7.  
  8. // Main Price
  9. $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
  10. $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
  11.  
  12. // Sale Price
  13. $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
  14. sort( $prices );
  15. $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
  16.  
  17. if ( $price !== $saleprice ) {
  18. $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
  19. }
  20. return $price;
  21. }
  22.  
  23. //https://www.templatemonster.com/help/woocommerce-how-to-remove-variable-products-available-price-range.html
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement