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.
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php /* Plugin Name: WP All Import Discount Price Plugin URI: http://www.yourwebsite.com/ Version: 1.0 Author: Steve Gates Description: A simple static plugin that has a function to calculate a price by a discount percentage. It creates nice prices, ending with 0.95 or 0.45 */ function wpai_discount($price, $discount=0.9) { return (ceil(($discount*$price)*2)/2)-0.05; } |
Now you can easily use it in your import config:
As second parameter you can use the discount you want. Use 0.9 for 90%, 0.5 for 50%, etc.
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.
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.Hi there
What if i wanted to add specific discounts to categories?
Example:
t-shirts (-20%)
Shoes (-10%)
Jackets (-5%)
Sincerely
Asger