Replace variable products price range
-
I have 2 code snippets where ;
Code A has the following functions:
Changed the price range to “from (harga terendah)+lowest price”
Displaying it on shop page
Hidden it on single product pageThis code works fine
Code B has the following functions:
Change the price format to ;
Thousands to ribu
Million to juta
Billion to MThis code works fine.
The problem is that when both codes are activated at the same time (I’m using code snippets), code A doesn’t work properly.
The shop page which previously displayed “from+lowest price” now displays only the lowest price (with the price format from code B).Please see the before and after display changes below :
Before using code A and code B > See
Using code A > See
Adding code B > See
I want > See
How do I get the two codes above to work properly when activated at the same time?
Any help is greatly appreciated.
Code A :
//Hide Price Range for WooCommerce Variable Products add_filter( 'woocommerce_variable_sale_price_html','lw_variable_product_price', 5, 2 ); add_filter( 'woocommerce_variable_price_html','lw_variable_product_price', 5, 2 ); function lw_variable_product_price( $price, $product ) { if(is_product()) { return $price; } // Product Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0]!==$prices[1] ? sprintf(__('Harga terendah : %1$s', 'woocommerce'),wc_price( $prices[0] ) ) : wc_price( $prices[0] ); // Regular Price $regular_prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); sort( $regular_prices ); $regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__('Harga terendah : %1$s','woocommerce'), wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] ); if ( $price !== $regular_price ) { $price = '<del>'.$regular_price.$product->get_price_html() . '</del> <ins>' . $price . $product->get_price_html() . '</ins>'; } return $price; } //Hide “From:$X” add_filter('woocommerce_get_price_html', 'lw_hide_variation_price', 5, 2); function lw_hide_variation_price( $price, $product ) { $product_types = array( 'variable'); if ( in_array ( $product->product_type, $product_types ) && !(is_shop()) ) { return ''; } // return regular price return $price; } Code B : add_filter( 'woocommerce_get_price_html','rei_woocommerce_price_html',5, 2 ); function rei_woocommerce_price_html( $price, $product ) { $currency = get_woocommerce_currency_symbol( ); $price = $currency .' ' .custom_number_format( floatval( $product->get_price() ), 2 ); return $price; } $n = 1000000; function custom_number_format12222($n) { $n = (0+str_replace("."," ",$n)); if(!is_numeric($n)) return false; if($n>1000000000000) return round(($n/1000000000000),1).' '.'-T'; else if($n>1000000000) return round(($n/1000000000),2).' '.'M'; else if($n>1000000) return round(($n/1000000),3).' '.'juta'; else if($n>1000) return round(($n/1000),0).' '.'ribu'; return number_format($n); }
The topic ‘Replace variable products price range’ is closed to new replies.