aristath
Supreme Deity
WPMU DEV Staff
Lifetime member
Support Hamster Likes (0)
Hello, I'm trying to create a custom Cash On Delivery payment method in Marketpress.
I have cloned and renamed the manual-payments.php file, edited it's contents just enough to rename everything and now my issue is this: The Greek Postal Service offers the option of cash on delivery but with an additional cost of €2.3.
So when someone chooses COD as their payment method, €2.3 mush be added to his shipping costs.
I have tried adding this:
$eltaprice = 2.3;
$shipping_price = $shipping_price + $eltaprice;
before line 113 and also tried some other variations but the shipping cost doesn't change no matter what I try.
Has anyone tried anything similar? Any tips?
Athens, Greece

Responses (14)
Support Kangaroo (joined March 2011) Likes (0)
Greetings aristath,
I am sorry that we will need lead developer input for this one though your coding efforts are fantastic.
In the past when this issue came up before, the member just added this as another item to be purchased, of course this is not at all a clean way to do it, but it worked.
Therefore I will see if I can get ANY lead developer in here with his invaluable insight into this plugin for his advice/advise for us.
Though this may take a bit longer then a normal ticket, I will try to get him in here asap.
Cheers, Joe
Support Hamster (joined March 2012) Likes (0)
@aecnu thanks! any help is greatly appreciated...
Support Hamster (joined March 2012) Likes (0)
While trying to "attack" this issue, I started analyzing a bit the internals of MarketPress and what we're trying to achieve and came up with this idea:
When a user chooses some particular payment gateway, we want the shipping to change.
So instead of trying to solve this issue solely by looking at the payment gateway file, we should be looking at the shipping!
So hypothetical: I have a custom shipping and a custom payment gateway (which I do). Inside the my-shipping.php file, right before the final
return $price;line (it's always to the end of the file), something like this should be added.Unfortunately the $payment_gateway part of that code snippet is hypothetical 'cause I haven't found exactly how MarketPress calls it (at least I hope it's there...) so if a dev comes in here taking a look at this that would be really helpful!
Developer (joined January 2012) Likes (0)
@aristath, Taking a look from my end. So I know you have been steadily hacking your own copy of MarketPress. What version are you running? I know we just pushed 2.6 last week. But want to make sure what I'm doing will be compatible with your plugin codebase.
Support Hamster (joined March 2012) Likes (0)
@PaulM thanks!! Your help and point of view is always valuable and helpful!
Actually I like to keep the MarketPress core intact so I haven't "hacked" anything. I hack while developing and once I reach a good point I move my hacks to my theme's functions.php. I find this is cleaner.
Anything you do will be compatible. I'm using the latest version available, stock.
(On a sidenote, do you guys happen to have beta-releases of your products available for community members? I think it would be great...)
Developer (joined January 2012) Likes (0)
@aristath, Can you send my your custom shipping file? That way I can us it on my own setup. Just upload to this thread as a zip or paste bin or other.
Cool about your development method. And yes we do sometimes release beta versions of MarketPress and other plugins to some of the known core users who are generally more familiar with the plugin than our own staff. Will make sure to include you for the next round.
Support Hamster (joined March 2012) Likes (0)
@PaulM I have attached my shipping file
Thanks again...
Support Hamster (joined March 2012) Likes (0)
Didn't attach correctly, pastebin: http://pastebin.com/gkVVNxHE
Developer (joined January 2012) Likes (0)
@aristath, Actually looking into hacking the flat rate shipping module (mp-flat-rate.php).
So the problem here is in the function for calculate_shipping() line 218 this is called when the shopping cart is displayed. And this is way before the checkout process starts and the user has selected a payment method. So not seeing a way to do what you are asking. Please advise how you want to proceed.
Support Hamster (joined March 2012) Likes (0)
I don't see that is a problem...
When checking out an order, the user has to go through these steps:
Cart, Shipping, Checkout, Confirm checkout, Confirmation.
If I'm not mistaken this function is called again and again on each step in order for the shipping to be displayed and is not cached.
It's only natural that the extra cost will not be displayed until the appropriate payment method is selected, that is the confirm checkout step.
Unless of course the shipping costs are cached in which case they won't be re-calculated on each step.
Developer (joined January 2012) Likes (1)Liked by: 
@aristath, Agreed. After thinking about this you are correct the shipping calculation is done on each step.
So back to your idea. The payment method selected is stored into a SESSION variable $_SESSION['mp_payment_method'] So you just need to check is that exists from your shipping function. Then you will want to check the value of it. In my testing I'm using the Manual Payments module. As part of that class the $plugins_name class variable is set to 'manual-payments'. So that is my check point. Add the following to your code prior to line 146 in the function calculate_shipping()
Support Hamster (joined March 2012) Likes (0)
@PaulM This is great!
I can't thank you enough... Marking as resolved and sending some rep points. :)
Support Kangaroo (joined March 2011) Likes (0)
Greetings PaulM,
Thank you so much for jumping in here and resolving this issue for me.
Great job as always!
Cheers, Joe
Support Hamster (joined March 2012) Likes (0)
If anyone tries to implement this, make sure you don't have any caching mechanisms enabled. If you do, then add you shopping cart url to the list of urls to be ignored. (that's a good advice no matter if you use this implementation or not)
Become a member