WP All Import: calculate discounts using your own function

Using WP All Import, I wanted to use a discount on our prices, but do the math myself. This way I could round the discounts by x.95 or x.45 instead of other weird prices.

The manual suggests you put your function in the functions.php of your theme. But I don’t want the function to be gone when updating the theme, and neither want to create a child theme just to put this one stupid function in. So I thought I’d create a plugin.

This seems to work perfectly. Just put in this code in your /wp-contents/plugins directory. Save this code to, for example, wp-all-import-discount.php.

Now you can easily use it in your import config:

WP All Import discountAs second parameter you can use the discount you want. Use 0.9 for 90%, 0.5 for 50%, etc.

 

4 thoughts on “WP All Import: calculate discounts using your own function

  1. Hi,

    how can I add custom % to regular price? Let’s say I want to add 20% to every price…

    Best regards

    • You can find such information on the website of the all import extension. If I remember correctly they have various examples on their website that explains how the import itself can be accomplished, with option as adding a percentage to your price.

  2. Can I use this to round the prices to a ‘nicer’ look. Like to round price of 399.82 to 399.80 ? I use the WP All Import mark-up function to get that price.

    • If you want to round like that, I think you can use [sprintf("%.2f", round(adviesprijs{1},1))] .. i haven’t tested this in WP All Import though, but in PHP this works. But then a price of 399.85 would show as 399.90.

Leave a Reply

Your email address will not be published. Required fields are marked *