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.