• Hi I’m trying to apply a custom formula to all prices. I need to apply it to the starting price, so it will condition also sales prices.

    function product_custom_price($price, $product) {
    if ( ! is_page( 'cart' ) || ! is_cart() || ! is_checkout() || ! is_page( 'checkout' ) ) {
          //HERE I GET PRICES AND OTHER VAR
            $custom_price = $product->get_regular_price();
            $custom_sale_price = $product->get_sale_price();
            $my_current_lang = apply_filters( 'wpml_current_language', NULL );
    
            //HERE I DEFINE FEES
          $ssivata = 7.93;
            $ivaitaperprezzofabbrica = 122/100;
            $arrotondamento = 4/10;
    
          //HERE STARTS CONDITIONAL TO APPLY DIFFERENT FEES TO SPECIFIC WPML LANGUAGES
            if( $my_current_lang =='it' ) {
            $tax = 122/100;
            $shipping = 6.5;
            }
            if( $my_current_lang =='en' ) {
                $tax = 120/100;
                $shipping = 24;
            }
            if( $my_current_lang =='at' ) {
                $tax = 120/100;
                $shipping = 24;
            } ECC.....
    
          //CALCUATE THE PRICE WITH APPLIED FEES
            $custom_price1 = $custom_price - $ssivata;
            $custom_price2 = $custom_price1 / $ivaitaperprezzofabbrica;
            $custom_price3 = $custom_price2 + $shipping;
            $custom_price4 = $custom_price3 * $tax;
            $custom_price5 = ceil($custom_price4);
            return $custom_price5;
        }
    }
    //FILTERS TO MODIFY PRICES
    add_filter('woocommerce_product_get_price', 'product_custom_price', 10, 2);
    add_filter( 'woocommerce_product_variation_get_price', 'product_custom_price', 10, 2 );
    add_filter( 'woocommerce_product_get_sale_price', 'product_custom_price', 10, 2 );

    The problems are it overrides the sale prices with regular prices and it doesn’t change variation prices.

Viewing 1 replies (of 1 total)
  • Thread Starter rgbear

    (@rgbear)

    Even with a simpler formula, I don’t get any change in variable prices:

    
    function adjust_lifetime_discount_price( $price ) {
    	return $price * 2;
    }
    add_filter('woocommerce_product_get_regular_price', 'adjust_lifetime_discount_price' );
    add_filter('woocommerce_product_variation_get_regular_price', 'adjust_lifetime_discount_price' );
    add_filter('woocommerce_product_variation_get_price', 'adjust_lifetime_discount_price' );
    add_filter( 'woocommerce_get_price', 'adjust_lifetime_discount_price' );
    
    
Viewing 1 replies (of 1 total)

The topic ‘Recalculate prices with filter’ is closed to new replies.