Skip to content

Instantly share code, notes, and snippets.

@trey8611
Created November 8, 2020 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trey8611/46daa3173f97300a5e4c30997bd70230 to your computer and use it in GitHub Desktop.
Save trey8611/46daa3173f97300a5e4c30997bd70230 to your computer and use it in GitHub Desktop.
WP All Import / WooCommerce Add-On | Adjust prices based on category or any other element

This function allows you to adjust your prices based on an element in your import. In this example, we pass the category to the function and mark-up prices based on that:

function my_adjust_price( $price, $element = '' ) {
    $adjust_map = array(
        'Monitor LED'          => 1.20,
        'PC Notebook Consumer' => 1.25,
        'TV LED'               => 1.30
    );

    return ( array_key_exists( $element, $adjust_map ) ) ? ( number_format( $price * $adjust_map[ $element ], 2 ) ) : $price;
}

Usage example:

[my_adjust_price({price[1]},{category[1]})]
@bruno-rc
Copy link

bruno-rc commented Jun 1, 2021

Thanks for the guide but when I do as written it doesn't work I forget something for sure ..
For example the "{column_4 [1]}" which for example in my case corresponds to the column of the price xml file where should I insert it?

@kot488
Copy link

kot488 commented Nov 6, 2023

Please tell me how I can improve the function. Increase the price of all products by 1.5 except those listed in the $adjust_map array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment