 Welcome back to the channel. In today's video, I'm going to show you how you can add different items to your cart. And when you go to view the cart and proceed to checkout, you should be able to see your country of origin, you should have a city. Then you should have something like a state, which is the district here. And we're going to have another dropdown, which is going to convert this village or town into something that we can select on our own checkout page. Now there are two plugins that I've realized that can help you to do this. I know in a video that I have done before, I've showed you how to code this, but there are actually two plugins that do this very well except they have their own limitations. Now those two plugins are one WC city select by eight manos. And then the other is state cities and places for who come us by Kingsley or two. Now I'm going to download both of these plugins and you're going to see how they work. So let's start off with either of them. I'll just copy this name state cities and places. I'll go into my admin dashboard. And then I'll go to plugins and click add new. And then I'll quickly search for this. I'll install it. And as it's installing, I'll just get this other name WC city select. And I'm going to go into my plugins right here and I'm also going to look for it. And it's this one by eight manos. So what I'm going to do is also install it and then we'll be able to use it. Now I'll activate the WC city select first. And when I activate it, we shall be able to see a city select. And then we shall also have a drop down for the different cities. So when I come here, we have Uganda here. I'm going to select a district. I can choose a beam and I don't have anything extra. But this particular plugin gives you the options of using the hooks and filters that are available for you to be able to. Extend what we have here. So what I'm going to do is I'm going to pick this filter. And I'm going to use it in a plugin that I'm going to add on. So you have the option to either add it in the functions that PHP or throw this in a custom plugin. So what I'm going to do is open up my editor. I'm going to open up my file here. And then I'm going to open a new folder and I'll call it states and cities. States and cities for wukamas. And then I'll drop this in my editor. And I'll open a new file and call it also states and cities for wukamas like PHP. I'll hit enter and then we'll have this available for now. I'll open my file with the PHP tag. And then I'll use the start plugin shortcut that I always use to help me with my plugins. So I'll add in the name and I'll say this is states and cities for wukamas. I'll change the plugin link. Now I'll just add my GitHub account. GitHub slash ITT. Take it first. Slash states and cities for wukamas. I'll change the plugin author and just add my name. Take it first. And then I'll say this adds a third level city to state. And then we'll have the version which is that. And then I'll just add this as a GPL to or later. And then we can always just use this right here. As our preferred or our prefix plugin name. So after doing that, I'll add basic security to this and say defined. So we're going to look for the apps path. If the apps path is defined, we shall go ahead and run the plugin. Or we are just going to die and say please get proper access. So I'll save that and then we shall start writing our plugin. I'll go back to this. I'll copy this. And then I'm going to come back in here and I'll paste it. Now this is a custom filter that is tied to the WC cities. And what I'm going to do is just use this function. And I'm going to add those cities inside the wukamas. So the country that I want to work with is Uganda. And I'll need to add in the UG for the country code. If you want to see these country codes. If you go to wukamas and then you're going to the internationalizations folder and then going to states, you'll be able to see the different countries that are there and then you'll be able to see like Angola is AO and so on and so on. So you have all the different country codes available for you in here. And this is how the different states are added. So I'll look for UG here. And then you're going to see that we have the different cities here and we have the codes that are attached to my country. So I'm going to look for a beam and I'm going to copy this code. So we have UG in there. I'm going to add this right here. And I'm going to say in a beam have let's say a city called Saqodi. And then we have another that we're going to call maybe blue tag. And then I'll just look for another location. I'll look for Kampala, which is the easiest for me. It's the city. So I'm going to get Kampala. So Kampala will be my state. And then in Kampala, I know I have Nakawa. And then I know I'm going to have Machindia. Machindia in there. So I'll save this. And all I'm going to do is now go back to the plugins right here. I reload and then I'll have states for cities for wukamas. And then I'm going to activate it. When I come back to a checkout and reload, you're going to see that before we had a field that needed to be filled right here. And now it has become a drop down. So when I select a beam, you'll see that we have Saqodi and we also have blue tag. So easy if I go to Kampala, if I look for Kampala, you're going to see that now the options available are Nakawa and Machindia, which I added through this particular extension of the code. So it's so easy, you use one plugin and then you can use it and then make your own filter and make sure that this is working. Of course, you can use this same code inside your functions.php. Now let's comment this out so that we can see the other plugin, which works sort of in a similar way. So let me go back right here in the plugins. I'm going to deactivate the WCC to select. And let's check the states, cities and places for wukamas. Now this particular plugin is a little bit different in that it already has supported countries. So you need to check if your country is supported right here. Then you'll be able to use that accordingly. So what I'm going to do is let me pick Australia from this. So in my checkout, I'm going to have Australia and after picking Australia, I'll look for the states. The states I'm going to go for Queensland and you will see that now we have Sabab showing up right here. And I can select a Sabab and say I'm going to be in Brisbane. So this particular plugin is supported by contributors and people who share their particular countries and all the states that are associated with them. However, it also has its own hooks like adding states and places. So let me go and see what filter hooks they have for us. I'll click on this and you'll see that we advise that if we want to add a state, we can either disable the state that is available or we can actually add some fresh states into the different countries that we have. If you want to add your location, you can support this plugin by going to the plugin repository on GitHub and you will add your new country and you can add more details. My biggest preference is just using this because it makes it so easy for me. Now I'm going to make a couple of modifications to my plugin so that when we don't have this plugin that we are dependent on, we get a little notice here that tells us that we need to have a particular plugin installed. That plugin is WCCTSelect so that we don't have our customer or our user confused about what's going on. So let me go back into my code and then we can begin working with that. When we come back here, we'll use an add action and the hook that we want to use is going to be plugins loaded so we are trying to get this that when the plugins are loaded we are going to run this particular function which is going to be checking whether we have WCCT available inside our plugin so we are going to check for WCCTSelect active. So I'll copy this function name and then I'll start the function right here and in here we're going to just say if and what I'll do is I'm going to look for a particular class that is run through when we start this particular plugin. Now I'm going to just open the files of this plugin so that we can see what kind of function we can tap into. So I'll add this here and I'm going to look in the file right here and we're going to see that this plugin already checks whether we have WCCTSelect which is a good part has this particular class called WCCTSelect so I'm going to check for it and we see that it is always activated here as a global so we can either check for this global or we can actually check for this class to see if it is actually active so I'll copy that class name and I'm going to say if not class exists so we're going to say if this class does not exist then we're going to actually make our notice available so we shall have add action and this is all part of WordPress so we're going to set admin notices and in here we're going to add another function that's going to trigger the admin notices for the WCCT active we'll say notice WCCTSelect and this will be the name of our function so I'll copy this and I'm going to set another function the reason why I'm doing this is I could write all the code under this if statement but sometimes you want to be able to either test your plugin and breaking it into granular functions makes that easy or it makes it easy to read your code so what I'm going to do in here is produce an admin notice so I'm going to first save this what we want to do in this particular case is we want to print a message we're going to output a formatted string so we're going to just print if and in here we'll add our quotes and we're going to say we want to have a div and that div is going to have a class and it's going to have a number of classes from WordPress like error then it will have notice dash error it will have notice then it will have is dismissible and this is dismissible allows us to have that little x and then we can always close this out whenever the user clicks that x button so we also need to close this div and inside this div we are going to add a very small piece of code that will allow us to extend this and also allow our plugin to be translatable into different languages so first I'll add its HTML it's going to be a paragraph and then we're going to add this percentage sign and the letter s and after we do that this will give us an opportunity to add the message that we want to pass as this percentage s here this message here as a variable will be replaced in this particular section so that's why we have it as s percentage sign or the modulus s right here so now I'm going to write the message here now in here we're going to have the sprint if which is going to turn a formatted string and in here we're going to add our translatable string so I'll first add this underscore there are two underscores that will allow us to translate the string that we're going to have in here and this is the message that we shall pass the message we shall pass is say states and cities states and cities for wukamas requires wc city select plugin to be active then after doing that I'm going to add a comma here and then I'll look for our text domain from here I'm going to pick it, copy it and then I'll add it here let me maximize my space now you will see that we have the string here that's going to be our message and then we are translating it right here which is actually good now if I save this and then come back to our page and reload you're going to see that now we have this little error message with our X button to show that it is dismissible and all we are saying is this particular plugin that we have activated and written requires to have this particular plugin that's deactivated now in the case that this particular plugin had not been installed we can attach an installation link right here so that's what I'm going to do I'm going to add an A tag for this here I'll add a href and in here I'll also add the modulus and the S right here and I'm going to close off this A tag right here now this will allow us have the same opportunity like we did have down here now in this particular case I'm going to add a comma here and then I'm going to add the string that links to the particular plugin that we want to have installed so I'm going to copy this right here and then I'm going to paste it here when I save this and come back here reload you're going to see that this is actually linkable and if I click on it you'll be able to see that the plugin that we are talking about is this very one so I'll hit the button and then we shall be able to see that this is active so I'm going to deactivate this and you'll see that message is not there when I activate this we have our message here if I activate our WCCT you'll see that that message actually goes and if I deactivate this there's no message activate no message which works very well if I deactivate this you'll see that we have that message coming back up so that is one easy way that you can improve the way your plugins work and the way that your customers and the people using your sites as administrators can actively get involved in having the site maintained and also not breaking it so if this is something that you enjoyed learning and it's something new please let me know in the comment section that this is the kind of stuff that you can find out how to use WordPress especially its co-functionality and then I'll be able to do more of this inside the tutorial so that you can pick it up and you can start writing professional plugins so that you can make some market and sell from them so now the only thing that's left is for us to get our code right here I'm going to uncomment this out and what I'm going to do is just get this add filter to the co-function that it calls and I'm going to place it under here and say if the class does not exist add this message and then return so that will stop the plugin from continuing but if the class exists it's sort of like writing the else and then putting everything in here or you don't need to write the else because this return helps us to break the plugin if this does not work but if this particular class exists then it's going to go ahead and then make a call to this particular filter and this filter will call this particular name so I'm going to just modify this by adding a prefix so that we don't have issues so I'll add take a press my cities and then what I'm going to do in here is go back reload this to see that nothing is breaking I'll activate the wcct select and I'll deactivate the old plugin that was helping us to add more cities and when I come to our checkout and reload here you'll see that in Uganda we'll have this open we'll need to select a district which is a beam and then we shall have our circody and our blue tag available just like we had it here inside our particular plugin so I hope to see you making more plugins and submitting them to the plugin repo because these are some of the small things that you can do to improve your experience otherwise don't forget to subscribe don't forget to like the video if it was good for you enjoy your day