Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @detmer1995,

    How can i combine ‘Adjust prices based on the price rang’ from: https://gist.github.com/trey8611/860a15ac342f1cd5cb34c5f93800974e with round price from: https://www.wpallimport.com/documentation/developers/custom-code/inline-php/ .

    You can use the “round_price” function, instead of “round”, at the end of the “my_adjust_range” function, e.g.:

    function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) {
        if ( ! empty( $price ) ) {
            // strip any extra characters from price
            $price = preg_replace( "/[^0-9,.]/", "", $price );
            
            // perform calculations
            return ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; 
        }
    }
    
    function my_adjust_range( $price ) {
        switch ( true ) {
            case ( $price >= 0 && $price <= 10 ):
                $adjustment = 1.7;
                break;
            case ( $price > 10 && $price <= 20 ):
                $adjustment = 1.6;
                break;
            case ( $price > 20 && $price <= 30 ):
                $adjustment = 1.5;
                break;        
            default:
                $adjustment = 1;
                break;
        }
        return round_price( $price, $adjustment );
    }
    Thread Starter detmer1995

    (@detmer1995)

    How can i call the functions combined in the regular price field? I’ve tried but only managed to get one of the two.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @detmer1995,

    How can i call the functions combined in the regular price field?

    It’s possible to combine functions, e.g.:

    [round_price(my_adjust_range({price[1]}))]

    Or, you can use my example in the post above, where I changed the code so that ’round_price’ is used in the ‘my_adjust_range’ function.

    Thread Starter detmer1995

    (@detmer1995)

    iI’m really sorry to ask, but could there be an error in the my_adjust_range function? Round_price works as excpected, but when i’m trying my_adjust_range the waiting icon keeps spinning forever. Doesn’t matter if i used my_adjust_range alone or combined with round_price.

    Using [round_price(my_adjust_range({price[1]}))] results in a forever loading icon.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @detmer1995,

    Yes, it sounds like something’s wrong with the my_adjust_range code that you have on your site now. Try deleting it and re-saving the original version (my updated version is no longer needed since you’re using round_price already).

    Plugin Author WP All Import

    (@wpallimport)

    @detmer1995,

    I’m marking this thread as resolved since it’s been inactive for a while. Please open up a new topic if you still have questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Combine round price with Adjust prices based on the price range’ is closed to new replies.