 Fungun Dar ntxu mo wyut sayo matati hivйurifumu kuw behimikilu Tagut musahishifu yу enxanjéd Paysez priwatur dance Kwan Nini sroka mkwa ina bi plug ins folder. Guzm風a nisa, Taikipres, Zunumumolo na owan maweza ina worda. Nao umarwa ina lewa. Kwao taikipres zunumolo ... Nao kusha wad kwa kwa gona kwa konwio ng معa ninafetik wa thaikipres nremi neza inad maweza tu kikasofu na wakam na ekstra fii fo datikula payment get ways na wa the first thing that I'm going to do is add an action and we are going to type into a wukamas hook wukamas wukamas kart calculate We are going to tap into the hook of wukamas, which is wukamas cut calculate fees. And here we shall add on our own method, which is a take-a-press, cut, fees, gateway. Not very descriptive, but it will help us with whatever we need to do. So I'll copy this and then I'm going to start writing our function. And with this hook, we actually get back an object that we can use and that is called the cut object. So with this cut object, if I was to use it, I can get the cut and then go to the add fee. There is a method that's chained to the add fee. And inside this add fee, you can actually add your fee. So we're going to choose a fee which we're going to call handling. And we're going to say for now it's maybe $5 and we're going to say this is true. So I'm going to save this and then come to my checkout page. And you're going to see when I reload, we have a handling fee of $5 here. But this is on every kind of payment gateway that I choose. I need to change this so that it can only work on one particular gateway. All the different gateways can have their own particular fees. So let's jump into the code again. So the first thing that I'm going to do here is say if we are in the admin area, if is admin and if the doing Ajax is not defined, because we want people to be able to see real time changes in the pricing, we're going to use things like Ajax to allow an auto update. So if that's not defined, then we are going to return. We're going to say you know what, stop whatever is happening and let us return. So let me properly format my code before we proceed. The next thing that we're going to do is we're going to look for the ID. So we're going to say the preferred payment gateway ID. That's what we're going to look for. And the way we are going to get this is by tapping inside WooCommerce. We check the session and we're going to get the chosen payment method. And that's what we are looking for. So we're going to go for chosen payment method. And what we're going to do to see this, we're going to just get this ID. And I'm going to chain it onto our title so that I can see it at the end of the day. So let me save this, come back here and reload. And you'll see that because we chose PayPal, it's showing PayPal. Let me reload. You'll see that we still have PayPal. And if I try to change to the other methods, we don't see this changing because we've not actually kicked our Ajax to actually run. So we need to have our Ajax running. And I'm going to show you how to do that in the code. So we'll say Ajax update on gateway change. So we'll add some comments here. And what we're going to do next is add action. And in this action, we're going to tap the WP footer hook, which will allow us to write our JavaScript or jQuery down below. So I'll add techie press Ajax runner. Make this an underscore and then get this and write out the function. So come here, write function, techie press Ajax runner and pass this in. At this point, we're going to check whether we are actually working with the REST API of WooCamas or we're working with the checkout page. And once this test is done, then we can run if statement. And inside here we're going to check is underscore checkout. And if it is not, is wc endpoint underscore URL. Then we're going to run the code. We shall escape the PHP and open the PHP down here. But in between here we're going to run our script tags. So duplicate this and close off the script tags. Now inside here we're going to do some JavaScript which I'm going to paste there and then explain what's happening. So what's happening here is I'm using jQuery and then saying when jQuery is loaded, we're going to check for a form with a class of checkout. And that is our checkout form that's on the end on the checkout page of WooCamas. And we say on change, if there is any change on this form, let's check for the input field that has the payment method. And once we get that, we're going to trigger an update checkout Ajax on the body of the code. So what we're going to do is save this and then let's come back and see what happens. So I'm going to reload this. When I click on this, you will see that we have COD coming up. When I click on this, you will see check. When I click on this, you will see BSC, PayPal and then we have Paleo showing up. So you can see the different methods that are available for us. So I'm actually just going to comment those out. And so we can know what we are working with. So we have COD, we have check, we have PayPal, we have BSCS and then we have Paleo. So these are the five different methods we have available for us to use. So the next thing that I'm going to do is say if the chosen method that we want, let's say we want to use cash on delivery. So we're going to say if we want to have cash on delivery, so I'll get this checkout ID, put it here and say if it is equal to COD, if that ID is equal to COD, then we shall pass in this figure. So I'm going to save this, come back here, reload. When I click on cash on delivery, you will see the five dollars. When I click on check payments, you will see that the handling fee actually goes away. So that's how you add this right here in our code. Now, I don't want to stop here. I want to extend this and say what if I had different prices for the different methods. Let's see that working out inside our code. Now, before I continue to that, I just want to add an if statement here to help us reduce errors that are going to happen. So I want to say let us return or let us do nothing if the checkout ID that we are looking for in the session is actually empty. So we're going to wrap this with the empty function and say if the checkout ID, if the method ID is empty, then we do nothing. But if it is something, then we pass in the handling fee. Now, if we want to have so many pieces, we're going to use it for each loop. We're going to just loop over each one of those IDs. And the first thing that we're going to do is that we're going to set an array of the different payment IDs. So in here, we'll say this is our chosen IDs, chosen methods IDs. And we're going to say it's going to equal to an array. And inside this array, we're going to have the different methods. So we'll say COD, or we'll just get what we have here and say the COD will be taking $3. Let me add the check now and add a check, PayPal, BSC and Paleo and give them different values. So with each one of these, I'm going to append a different value. Maybe for check it's cheaper to process it, so $1. PayPal takes a lot of money, so we'll say $4. BSC will take maybe $2. And then Paleo, which is mobile, is going to take a lot of money. So we'll say maybe $6. So these values that I'm putting here they will take in the currency value of your wukama setting. So with this array, instead of just having this if statement, I now need to change it to a 4-ish loop so that we loop through each one of these methods and then get the value. So we're going to say for each chosen method IDs and we're going to say as chosen method ID and we're going to get the value of each. So we're going to say amount. We'll then push our if statement through here and say if the chosen ID which I'm going to get here and replace this to make it dynamic, we shall say if the preferred ID, gateway ID we have here is equal to the chosen method ID here, then we are going to get the amount and put it here. Of course I'll remove this. This is what we put to debug. I'm going to change this 5 and then make it dynamic. So I'm going to put our amount here and save this. So let's come back to our front end and then reload this. So when I go to direct transfer, you will see we have two check payments. You'll see we have one cash-on delivery. We have three PayPal. We have four mobile payments. We have six. So you can actually make this into a fully fledged plugin even sell to other people. All you need to do is make sure that it has wukama setting so that these can be dynamically added so that anyone who wants to do this is able to do it. So if you want to see how that is done, I have a video that is already in the link below that you can use to help you make this dynamic and these are fields that you can always get from your wukama site in the admin area and just put them inside your IDs right here. So if you really enjoyed this, please give it a thumbs up, share it with your friends. Let me know in the comments what you think about all of this and don't forget to subscribe if you haven't yet considered. Otherwise, enjoy your day.