Skip to main content

Batch script to update WooCommerce product titles

I had a client who had named all of his 600+ products to uppercase and Google Shopping was not allowing the products to be indexed because of this.
To automatically rename the Woocommerce Product titles, I ran this script:

This will loop through each product and rename the titles to capitalised using php UCWORDS()

For example: MY PRODUCT will be renamed to My Product.

Read More

WordPress SMTP without any plugins

WordPress is a very good CMS, BUT! I hate plugin bloat. I’ve seen so many websites use a huge amount of plugins to cover every little feature, which contributes to speed issues and can cause problems down the track.

There are heaps of SMTP Plugins for WordPress available so that you can use AMAZON SES , SendGrid, MailGun, etc. The easiest way to set up SMTP is to add this snippet to your functions.php file, this will ensure that WordPress uses SMTP instead of the standard PHP Mail.

Add this to your functions.php file and configure how you need to. Then save it.

// USE SMTP
add_action( 'phpmailer_init', 'setup_phpmailer_init' );
function setup_phpmailer_init( PHPMailer $phpmailer ) {
    $phpmailer->Host = 'HOSTNAME'; // eg. email-smtp.us-west-2.amazonaws.com
    $phpmailer->Port = 587; // could be different
    $phpmailer->Username = 'ENTERUSERNAME'; // SMTP Username
    $phpmailer->Password = 'ENTERPASSWORD'; // SMTP Password
    $phpmailer->SMTPAuth = true; // Set to true if login is required
    $phpmailer->SMTPSecure = 'tls'; // enable if required, 'tls' is another possible value
    $phpmailer->IsSMTP();
}

Hope that helps!

Jquery Date Range – Restrict To and From Dates easily

Recently, I had a request from a client to have a datepicker that restricts dates based on the start date. Using Jquery Datepicker, I created a TO and FROM date, where by:

  • The Start date must be 14 days or more from today
  • The End date must be 7 days after the start date
  • The End date can only be maximum 28 days from today

To do this, I created two fields, one for the start date, one for the end date, then JQUERY did the rest.

To start, download JQUERY UI from here and include it in your project.

<label for="suspstartDatePicker">Start Date</label>
<input type="text" id="suspstartDatePicker" name="suspendfrom" class="form-control-lg" placeholder="Suspend start date">

<label for="suspendDatePicker">End Date</label>
<input type="text" id="suspendDatePicker" name="suspendto" class="form-control-lg" placeholder="Suspend end date">
                       

Then I added Jquery UI Datepicker in the footer of the page, below the JQUERY UI js script.

<script>
$("#suspstartDatePicker").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
minDate: '+14',
 
 
onSelect: function(selected) {
var date = $(this).datepicker('getDate');
var limit = $(this).datepicker('getDate');
 
date.setDate(date.getDate() + 7); // Add 7 days
limit.setDate(limit.getDate() + 35); // Add 7 + 28 days
 
 
 
$("#suspendDatePicker").datepicker("option", "minDate", date);
$("#suspendDatePicker").datepicker("option", "maxDate", limit);
 
 
$('#suspendDatePicker').val('');
}
});
 
$("#suspendDatePicker").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
multidate: true,
 
});	
</script>				

Hope this helps!

Simple WordPress User Restriction Tutorial without using Plugins

When you need to restrict users in WordPress, there are heaps of plugins you can download. Personally, I think too many plugins is a bad practice in WordPress, it can lead to “plugin bloat”, where your website can be slowed down and you’re reliant on too many plugins to make your site work.

In the video below, you will see how I manage user restrictions quite easily using a must use plugin in WordPress and a few minutes of my time.

Read More

Load an AJAX PHP file from WordPress

On my website, I have a caching plugin called WP Rocket, which is an awesome plugin, but one downside is that if you have dynamically generated content, it will be cached.
For example, on my website, I have a cool PHP widget that figures out the current time, and then displays a message based on the time. With caching, that plugin will no longer be dynamic because it will just show the result from the time that it was cached.

Read More

Replace WordPress post date with hours and days

Today I found a really cool and simple way to change your WordPress post archive to display how long ago the post was made as opposed to the date. It gives your visitors a very fast indication that the post is new so they don’t have to think twice about today’s date.

So, basically instead of the post saying “Posted 10/10/16” – it will say, “Posted 2 hours ago”, or “Posted 2 Days ago” etc.
Read More