 We're going to be starting the next talk. Next talk will be by Barry Harris, and he's going to be talking about how to do snippets to boost your hook-commerce website. A round of applause. Thanks, Martha. Can you everybody hear me okay? Perfect. So two things are at the front. One, I'm from Newfoundland, so I may say some words that you don't understand. And two, I may speak fast. So if I do, let me know. So yes, I am that whole. So for people that don't know, that is a Radio Shack Color Computer 2. That was my first computer system that I learned that had a version of basic on it. The first one I purchased did not have any way to save data, so if you turned it off, you lost everything. It started over fresh. My next upgrade was a cassette player where I could record and save programs too, and you would have to actually listen to the tape, wind it forward until you got a blank, push, play, and it would load code into the computer. My next upgrade was a hard drive. No, that's a lie. My next update was a five and a quarter inch floppy disk, which had 360K of data available on it. So my next upgrade was a hard drive, which had 10 megabytes of data. So that's where I started. So I spent 34 and a half years in the military as a logistics person, beans, bullets, and gas. I found that if you get that right, everything is golden. A vehicle accident in Kosovo in 1999 started my release process from the military. What happened was I was rear-ended in a motor vehicle accident, and it injured my back, so I could not carry on doing soldier-like tasks, like carry a 50KG rucksack, couldn't do the farmers' carry where you're carrying a 300 pound or the same weight as you on your shoulder out of a building. So I couldn't do that. So in 2012, I finally said, I can't do this anymore, and they started the release process to release me out. So I've always enjoyed computers. In 1999, in Kosovo, I was working out of a sea container because we didn't have any offices. So I was in the logistics in supply, actually, so we had spare parts and the beans, bullets, and gas. We had a computer system that was archaic then that you had to do all your receipts first, then you do all your issues, and then you do all your adjustment transactions. And you had to do them in that order because if you'd mixed them up, if you did your issues before your receipts, you would get errors, and your inventory would be out. So we had a technical visit team come in, and they were using barcode readers back then, and it blew me away. They would scan an item, get the quantity, adjust the quantity, and it saved it to a database CSV file, and I said, what are you doing with that CSV file? And they said, we're going to, when we get back to Canada, we're going to upload that to the database, and your inventory will get updated, and I like it. Can I email that CSV file to the data clerk who was in Montreal? And the guy said, I don't know, so he linked us up. So I wrote a program in Visual Basic that did all our transactions, created the CSV file, and every morning I would send her off the CSV file. So our inventory was always up to date. That was my biggest program back then. So I was released from the military in 2016. Part of the program with the military is they have an insurance program through manual life where if you are injured, they will retrain you. So I went to BCIT and took a web design course. So I did that for a couple of years, found out that I don't like design. I hate designing websites. I still do some, but I hate it because design is very personal to people. So I'm working on my Bachelor of Science with Athabasca right now. I'm 80% done, eight courses less. I started my business in 2016. I did not know anything about website building business. So I got on, I was googling websites that had poor design, and I was reaching out to the owner and say, hey, your website sucks. Do you need help? And my very first client was a fellow veteran who was running an auspice retreat in Nova Scotia, and they said, our hosting guy just died. And we don't have any hosting anymore. Can you do it? So I agreed to take on those guys, and they're still my client today. I did their website for nothing. But the beauty thing about that was they told people. So they told people. I gained more business. And the more work I did, the more referrals I got. I discovered WordPress, WooCommerce, I would say, about 2018, because I was writing websites by hand with HTML, CSS, JavaScript, and PHP. And updating those, it just was, I did not have the time for it. So here I am today. I'm a freelancer. All my own business. I'm out of Vegas, EPC. I have 350 websites under my belt to date. And I have not marketed yet. I don't think I will ever have to. Because WooCommerce and WordPress, there's enough work out there for everybody. So here's what I use for my development setup. I have a Mac Mini M2 that I use as my main coding machine. I like it for speed and graphics. I like the Adobe suite on it for doing my graphics and my videos. My text editor is sublime text. I have used others. I have used visual code, but I like sublime. I use a software package, local WP, on my local computer to develop all my websites on. So I keep a local copy on my local WP. And this is free. What I like about it is it has an email capture part built into it. So when I'm testing websites, the emails never get sent out. The emails get captured within the system. And I test all my sites on Chrome, Firefox, Edge, Safari. I used to do Opera, but the user base was not there. Those four capture about 98% of all web browsers out there. I also test on iPhone and Samsung. I do have a Windows system that I use, and I have several Ubuntu systems that I use to test on. I use DreamOS as my main web hosting company. They're one of the top three recommended by WordPress. I also have websites on OVH, Web Hosting Canada, Cloudways, Kinsta. The OVH one is interesting because when they had the fire in their server firm, a lot of websites went down. Not mine because mine were in Canada, but I learned a lot about backups then. One of the great things about DreamOS is their staging process. I can have a staging and a live site being hosted together, and I can migrate easily from one to the other. Some of the hosting packages that I have learned not to like, and I'll tell you why in a bit, are any of the hosting packages that are owned by Endurance International Group, EIG. These include Doxter, Oskater, there's iPage, there's a whole bunch of them. The reason I don't like them is not that they're not good hosting platforms. What I don't like about them is they don't give me access to the actual server itself to touch it, and I like being able to touch the actual files on the server. These guys do not like to do that. We went to some caveats on my talk. When coding for WooCommerce and WordPress, use the coding standards. They provide you with a good example of how to properly code. If you follow the coding standards, your code will be fine and it will live on through different updates to WordPress WooCommerce. Always sanitize your data and escape your data. What do we mean by that? You don't want people inputting stuff into your forms and your fields that contains JavaScript or code that will trick people into doing stuff with your website. If you don't sanitize or escape your data, people can import JavaScript into and then take over your website. Always use a child theme. I cannot stress this enough because if you make changes to a theme in WordPress and don't use a child theme, any time the theme updates, all your changes are lost, so always use a child theme. Functions.php is a file inside of the child theme that you can also put all of these code snippets that I'm going to give you into the child theme. The difference between the PHP or Functions.php and the code snippets is that if you ever want to change themes, you've got to make sure that you take your Functions.php. If you use code snippets, I can export from one website, change the theme, and carry on. One of the things that I found out early is when you're copying and pasting from the internet, be very careful of quotes. The quotes that you see on a website are not necessarily the same quotes that you need in your code. And test, test, test. WordPress hooks. This is where we get into the meat of the lecture. So WordPress has actions and filters. The main difference is actions run a function at a specific time. Filters modify the data that's in an already existing function. And you can tell the difference what they are in the code. If you're looking through a code and you see a do action, that's an action hook. If you see apply filter, that's a filter hook. So when you're changing up your code and you're looking into the code for WordPress and WooCommerce into all the PHP files, the different classes, and I highly recommend you get in there and find out how they actually do things, because that's how I learned. I got in there and I actually played with the code and said, what if I do this? What if I do that? Can I change this? What if I do this? And that's how you learn. The biggest things on actions and filters is an action will return nothing. It'll just change the way that a function works. A filter will always return something. And we'll get into what the differences are. So here's an example of the actual code from these files within WooCommerce. So in the orders.php file, you will find this do action WooCommerce before account orders pagination. That is a action hook that you can touch now using snippets. And then the WooCommerce shipping code class, there's an apply filters where you can apply to different shipping methods. So you can add your own shipping methods to WooCommerce. And the references are there. Business Bloomer, I use this site, not daily, but I use it a lot created by a former Word Camp presenter Rodolfo. He has built some great visual hook guys where you can actually see the actual place. These are the actions and filters where you can inject code into the different sections of your WooCommerce. So what are snippets? Those are just basically short sections of PHP code that you can inject into your site. That's all they are. Where to find them? Google is your friend. The only caveat is you got to test everything you take off Google search engine because some of it is outdated and some is not updated to the newer versions of WordPress WooCommerce. WooCommerce, they have their own section, code snippets that you can use. Rodolfo, that's Business Bloomer. Him and I have collaborated on a couple of websites. When I had a problem that I couldn't solve, I went to Rodolfo. He's in Italy and he was worth every penny I paid him. The guy is brilliant. Michael Erickson, well-known PHP coder, WordPress guy. On limited WP, they have a bunch of snippets you can use and WP Explorer, these are just some. If you just Google WordPress code snippets or WooCommerce code snippets, you'll have enough to read for days. So now that you have a code snippet and you understand what you want the snippet to do, how do you add it to your WordPress WooCommerce site? One, you can add it to the child theme in the functions.php file. What that does is every time WordPress loads a page, it loads the functions.php and that code is available for that page to use. The other two are plugins. They are both good. I use both. So I would say code snippets, 80%, WP code for 20%, but WP code, if anybody used insert headers footers plugin in the past, they're the same people. So they allow you to insert code into your header and footer and now they also have where you can input snippets into your pages. So should I use a snippet, should I use a plugin? There are plugins for most of the code snippets that are out there. The only thing that I balk at is the more plugins you add, and especially if they're not coded for speed, they'll slow down your website. So I am a fan. I have used all of these plugins, but I nowadays, I would say 75%, I use code snippets instead of plugins. And a lot of these are paid plugins. So this is basically what a code snippet looks like. And there are use cases, and I'll explain what the use case was. These are short code snippets. You can have code snippets that are 1,000 lines long and more. So we had this one website. They sell liquor products online. They have 5,000 products. We pull their inventory from GlobalTill, which is a major POS system. And we pull their inventory every 15 minutes from GlobalTill to update the WorldCommerce website so that their inventory is up to date. Problem is, every time it updates an inventory, every 15 minutes, there's an action scheduler that runs, and it saves a log file. So my web host sent me an email one day, says, hey, what are you guys doing? Your database is 1.5 gigs. Trim it down. So I go in and look, and the table for action scheduler was 1.5 gigabytes, one table. Wordpress, WooCommerce retains that data for 30 days. So how do we get rid of it? Let's go back up. The back end code, there was a filter called action scheduler retention period that tells WordPress, WooCommerce, how long to save the log files. And these two are the same process, just the timing is different. And it's very easy. So all you add to the code snippet is add filter, areas where we want to attach it to, areas to function we want to run, which is the same as this, and it returns, remember functions always return something, weekend seconds, which is a standard, which the number of seconds in a week. So what this function does now is it only keeps the logs for one week, then it wipes them out. This one does it, what we found was even when we added a week, we still got over a gigabyte in data in one week, but then we just changed it to this, and the web host was happy. So now we're going to get into the different types of snippets that I use all the time for WooCommerce. There are actual product snippets that show on the product pages, cart snippets that will show on the cart page, checkout snippets that show just on the checkout page, and then there's miscellaneous snippets. And I got about four or five of each just to show you what can be done. So product snippets. So this little snippet here hides that. So if you don't want to show the product made of data on your product page, this little bit of code removes that. This number here is the priority for running this snippet. You will see when you look at the WordPress WooCommerce code, a lot of the functions in the action and filters have a priority. If you set your number to a number that is lower than what's there, it'll run before that one runs, if you do it after, it'll run after that bit of code runs. If you do it the same, it replaces it. So this one is the same. So it just replaces this, removes that. WooCommerce pages. There are tabs that show a description, additional information. You can have a shipping tab here. This one, code, removes this tab. And you get into the code, you can remove that. You can add them. You can add your own tabs. Can you CSS to hide this? Right? Because this comes with its own class, NID. You can use CSS to hide it. When you do CSS to hide and set the display to none, the code is still in the back end code. It's still there. It's still getting searched, it's still getting part of the index. Using a code snippet, takes it up, never gets seen. This little snippet, some themes have a breadcrumb. This client did not want WooCommerce breadcrumbs, hated them. So a couple lines of code, took it out there. We could have used the child theme and changed the template file in the child theme to remove it as well, but this was simpler. This one was a little bit tricky. One of our top websites is another liquor store. By the way, liquor stores and cannabis stores are the two most popular clients I have nowadays. Since COVID kicked in, these guys all wanted to be online. So this one client, they're on track, they're going to do 10 million sales on their WooCommerce site this year. They run a sale once a year where they have a special product that they bring in and what they did not want was one customer coming in and buying the whole lot. So what this does is it limits any one order to two bottles. The reason there is so much code here that is longer than the previous snippets is because in WooCommerce you have things that are called simple products and you have things that are called variable products. And this does the simple products, this does the variable products. Limits them both to one bottle. Limits them to two bottles. And this item was very, very popular. Like I say, people wait once a year when they do their mail-chimp mail-out. People are just hungry waiting for the sale to start. This is one, the client wanted to know this because they used a third party to create their stuff. So the third party needed some lead time. So this notice, they wanted this notice to show on all their products that required extra shipping. And the way we got to select the products is not included in there is we used a query that if the product ID matched the products that they were at extra shipping requirements, this message shows. Any other products that they did not need at the time of shipping, message doesn't show. And there's different, there's some different use cases that you can use this for. And this is another example where we use just one product using the product ID. So if it is this product, show this message. You can also use this, let's say you have 10 products, just use an array of product IDs, loop through it, if the product ID is in the array, don't show it. This one was not tricky but was interesting and we couldn't understand why the client wanted to say that one each. We couldn't understand that. But the client wanted it, so we coded it. We haven't figured that one out yet. But it was just a couple lines of code. Now we're going to go into some cart snippets. This client wanted us to show on the website how many items were in stock. So if the customer saw there's only one in stock, maybe it would have impressed them to buy it because there's limited stock. This was a little different one because we have, there is a couponing system in WooCommerce that you can use but they wanted to show the customer how much off they were saving when they purchased their item. So because there was a lot of code there, this is what they wanted the customer to see, the regular price and the sale price. They wanted to see the discount amount to show on the cart page, not the product page but on the cart ship, on the cart page. This was for one of our liquor stores. They had a shipping and handling fee that they wanted. You can get a plug-in that I had, shipping and handling fees. But they wanted to have $10. Wanted to show us shipping and handling fee on the cart page. And this is what it does. It automatically totals, automatically updates with just those few lines of code. This one, you may have noticed on some websites, WooCommerce, when you change the quantity in the cart, you have to click Update. This code, since anytime there is a click on the quantity changer, it automatically updates for you. And what we did as well is we used CSS to hide the Update button because you didn't need it anymore. Here's something that a lot of clients asked for in that when they have somebody on their cart page is they don't want them leaving their cart page. They want them to go through with the checkout. They did not want links to their products on the cart page. There, there's the link, there's the link gone. This one, our client sold one product. They did not want people going to the cart page. They wanted to go from Buy Now to Check Out. And what this code does is it updates the buttons, gets rid of Add to Cart, Buy Now, and it's there twice because you have simple and variable products. And then, when it's done, it just redirects to the checkout. Now we move on to some checkout snippets. Every WooCommerce installation comes with company name optional field. They didn't want that. This bit of code takes out this. All of the fields that are in the billing can be removed by on setting them. So if you want to remove any of those, just use this code, on set the ones that you don't want, like building address line 2. Very, very few people use that. There is a caveat. Most payment gateways require the name, the address, and phone number for fraud detection. You can do the same thing with these shipping fields. You don't want them, on set them. This client wanted us to have a shipping field. They shipped flowers, but they wanted the recipient's phone number in the shipping field. So this code, and it validates as a phone number required, can be true or false. There's a text. The type is a telephone. There's a text that gets shown. I don't have one. It saves it to the database, retrieves it from the database for the order. This one was a little interesting, and it made sense for cart abandonment. On a normal WooCommerce site, the email address is way, way down. If you capture it up front, that gets saved to the database, and you can do cart abandonment with it. With these few lines of code, move the email address up to the top. Made the priority number one. This is one where our customer had free shipping over $200. If their customer's order meant that, they did not want to show any other shipping methods. Just show it a free shipping. And this is the code that we put in. And what it does is it goes through an array of all these shipping methods on the site. And if free is available, it sets it up as free as the only rate, breaks, and returns. The shipping method. Here's another one. The client did not like the coupon at the top. They wanted the coupon at the bottom. So we moved it to the bottom. What this did for them, believe it or not, is they got more full-price sales. Believe it or not, even though they sent out coupons, they got more full-price sales because coupons took away from their profit merge. Trust image. This client wanted to let people know that their system was secured by PayPal. You can use Moneras. You can use Stripe. You can use Square. You can use any image. And this image is straight from PayPal, right? Here's the source of it. It is approved for use by PayPal on your website. And all this code does, puts this image there. There's no link, but the image is there. You could wrap this in an A tag with the link to PayPal. Why would you? Don't give your customers a chance to leave your cart or checkout page. Now, these are miscellaneous snippets that did not fit anywhere. They're not product. They're not cart. They're not checkout. This is one. There is a plugin out there called Follow Up Emails that will send emails out to your customers and say, how did we do? There's a code snippet. You pay for it. There's a code snippet. This little bit of red here is a link to a Google reviews page for the business. So they are sending an email. Seven days after the order is completed, they're asked, can you please do a review on Google for us? And they are getting tons of these getting filled out. We had a client that went away on vacation for two months, and he didn't want to shop to sell anything. So what do we do? If the user is not logged in, i.e., not an administrator in the back end, remove, add the cart button, remove the pricing, remove so that nobody can buy from the website. There was a paid plugin that does this. It was a little, how shall I put the word, cheat? They had a third-party email, and they were being charged by the number of emails being sent out. I said, well, let's change your email provider. No, I've been with these guys for years. So they wanted to turn off as many emails going out from the system as we could. So whenever somebody changes a password on the website, it sends out an email. So we just turned it off. So no longer sends us password change. And you can do that for just about any of the emails being sent out. Here's one I use. Don't do this on a live site. Do this on your testing site. And what it does, this little snippet will show you the actual items in the cart array for troubleshooting. So if I have a problem that a cart has not got the number of items, or I put this snippet in and I get to see what's in the cart. I use this one all the time. Again, don't use it on a live site. This client, they operated a boutique invitation-only website. If you were not invited to the website as a customer, you could not buy. So the way we've got around that, or the way we've implemented that functionality is we set it up so that if the user is not logged in, we send them back to my account page to get them logged in. You don't log in? You can't buy anything. Share this slide. Yeah. I've provided these slides to the WordCamp team, and I think they're going to be available. If not, pop me an email, and I'll gladly email them to you. So this is the continuation of these people, if they're not logged in, this is what they see. Cannot see the prices? Must log in. Now, just so you know, all these images and stuff I'm showing you, these are not my live sites. I built this for this conference. This customer wanted the shipping methods sorted by price. Cheap is at the top, most expensive at the bottom, and there's the magic code there that does it. It returns it, and that is my talk today. So here's my website, LinkedIn, email, phone number, any questions you want to join up on LinkedIn, feel free, you want the presentation, email me. I will gladly send it out. Okay. Do you want to ask any questions for him, before, or can I always email? I don't want three o'clock. One more conference. Any questions at all? Okay. So I will carry on, because we have a few minutes. Oh, okay. So my journey to this, like I say, has been long, but once I found WordPress on WooCommerce, I fell in love with it. I like that you can actually touch the code and change it and make it do what you want. Can it be better? Sure. It keeps getting better every iteration that comes through. I've been using WordPress since 2016, and every improvement that comes through, and I have submitted stuff to WordPress, and the app came back with questions, and one of my items they did take. So how do I get business? Like I say, I haven't marketed at all. So what I found effective for me is Facebook and LinkedIn. I write blog posts on the website on a regular basis, but for Facebook and LinkedIn, I belong to certain groups, WordPress, WooCommerce, small business. I lurk in those groups, and I answer questions that people ask. I don't seek any money. I just, you know, if I know the solution, I will put it in. And what I have found is, one, it builds credibility, two, I get work. People will say, hey, can you do that on my website? Sure. And away we go. So Facebook, LinkedIn have worked for me. A couple of tools that I use that I didn't mention is backups. I use all-in-one migration for migrating websites back and forth from staging to live. And the second one I use is Migrate, not Migrate, ManageWP from GoDaddy. I have all my sites in there. I can go in, one click of a button, see what needs updating, and I can update it right from there. Those are two of my go-to. Thank you.