Gerhard Potgieter

WordPress / WooCommerce Engineer at Automattic

WooCommerce 3.2: Add back option to resend admin order email — October 13, 2017

WooCommerce 3.2: Add back option to resend admin order email

Since WooCommerce 3.2 the option to resend the admin new order email was removed. The reason was that it was a pretty much-unused feature as admins already have access to the orders so they could just look it up.

However, if you relied on this feature for some reason and now all of sudden can’t use it, fear not as it can easily be added back with the following snippet.

As always include the following code in your theme’s functions.php file omitting the opening <?php tags

Advertisements
Installing PHPUnit on Mac OSX — October 12, 2017

Installing PHPUnit on Mac OSX

So you have an Apple Mac and want to get started in the wonderful world of Unit Testing. Writing a unit test is very straightforward, yet most open source software projects have very limited unit tests available so always welcome more and it could be an easy way to contribute to the project.

Like I said writing your first unit test is pretty straightforward, it can be something as simple as just checking if a constant is set $this->assertFalse( defined( 'WC_TESTING_DEFINE_FUNCTION' ) );. Yet when it comes time to run the actual test you quickly discover that you need to have some software installed on your machine to run this, PHPUnit in WooCommerce’s case.

Then you head over to https://phpunit.de/getting-started.html and copy and paste the command and find that it does not work on your Mac because Mac OSX does not ship with wget installed by default. Then you search for installing wget on your mac and you go into a deep rabbit hole of having to install all sorts of software just to get it working.

Luckily there is a simpler way, simply copy and paste the command below into your console to have PHPUnit installed.
php -r "copy('https://phar.phpunit.de/phpunit.phar', 'phpunit.phar');"
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit

WooCommerce: Hide refund reason from customers — October 9, 2017

WooCommerce: Hide refund reason from customers

Refunds can be a sore subject but it is something that every store has to deal with, keeping track of refund reasons can be very beneficial to you so you can keep pushing your refund rate down further and further.

The problem is that you do not always want your customer to see the reason you enter for when doing a refund, which WooCommerce will display by default to each customer.

Good news is that you can easily replace the refund reason in your customer-facing emails and pages with static text like just “Refund”.

Add the following code to end of your theme’s functions.php file omitting the opening <?php tag

 

WooCommerce: Do not allow account creation with fake emails — November 16, 2016

WooCommerce: Do not allow account creation with fake emails

ECommerce is serious business, that is why when a customer signs up to your store you want the most accurate information to stay in touch, promote your products and offer decent after sales service. Unfortunately, there are lots of chancers out there on the internet that use fraudulent cards and fake emails to purchase products from your store, which can leave you to foot the bill.

The following piece of code will prohibit usage of fake emails for creating accounts, it focuses on sharklashers.com but can easily be expanded to include other email domains by just adding to the array.

Add the following code to end of your theme’s functions.php file omitting the opening <?php tag

Uploading Files With wp_remote_post Or wp_remote_request — July 30, 2014

Uploading Files With wp_remote_post Or wp_remote_request

My job at WooThemes enables me to work on all sorts of cool projects and enables me to push the limits of what is possible with WordPress each day. Some of the projects I work on that I enjoy the most is projects that involves interfacing with any sort of API service, I am a sucker for an API 🙂

In a recent project which involved interfacing with an API service I had to upload a file to the service, and wanting to stay true to the WordPress way I naturally built the whole API interface layer using native WordPress functionality. This involved making use of the wp_remote_request function, which is called by the wrapper function wp_remote_post to send through POST requests.

After Googling for quite a while I just could not get any examples of uploading files in binary using wp_remote_post or wp_remote_request, for that matter, which resulted in me having to figure this out on my own.

The API document was straight forward, in order to upload a file you need to post it as binary to API endpoint, now there are plenty of example of doing this using cURL, so I used that as a starting point and converted it to WordPress native functionality.

The cURL way of uploading the file

Digging through some cURL docs I found that I basically needed to set a header to binary, and then stream the file binary content as the body, and found the following way of uploading the file using either wp_remote_request or wp_remote_post

The above code shows examples of using either wp_remote_request or wp_remote_post, as you can see there is not much difference between the two, instead that with wp_remote_post there is no need to set the method header as it is a wrapper function that does that automatically.

In some cases API services will require you to do uploads with PUT requests instead of POST, in that case you will use the wp_remote_request function and just set the method header to PUT instead of POST to make a PUT request.

Hope this helps someone out there that has also struggled to do this using native WordPress functions.

 

 

 

WooCommerce 2.1 Add Confirm Password Field at Checkout — February 25, 2014

WooCommerce 2.1 Add Confirm Password Field at Checkout

WooCommerce 2.1 Confirm Password Field on CheckoutThe last couple of weeks I have spent a lot of time working on some tutorials to reverse some of the changes introduced in WooCommerce 2.1 to the ways it was in WooCommerce 2.0.

This tutorial is another one of this cases, WooCommerce 2.1 removed the password confirm field and functionality from the checkout page as it was thought that should a customer make a typo in the password field they can easily just reset it via the password reset functionality in WooCommerce.

However if you would still like add this password confirm field to your WooCommerce 2.1 checkout page, good news is this is still possible.

The code below will add an additional field underneath your password field on the checkout page called Confirm Password and when the customer places the order it will check the two password field against each other and give an error message and prohibit checkout if they do not match.

Place the code below in your theme’s functions.php file

WooCommerce 2.1 Grouped Prices Revert To WooCommerce 2.0 Format — February 24, 2014

WooCommerce 2.1 Grouped Prices Revert To WooCommerce 2.0 Format

WooCommerce 2.1 Grouped Product Prices, Revert to WooCommerce 2.0 Format

 

Last week I did a tutorial that showed you how to change your WooCommerce 2.1 Variation prices from the new range format to the old WooCommerce 2.0 From: format, that tutorial however only included changing the prices of variable products.

The following tutorial shows you how to modify the Grouped Product prices that also uses the new range format in WooCommerce 2.1 to the WooCommerce 2.0 From: format.

To change the pricing format for your WooCommerce grouped products add the code below to your theme’s functions.php file

WooCommerce Show Trailing Zeros on Prices — February 21, 2014

WooCommerce Show Trailing Zeros on Prices

WooCommerce Show Trailing Zeros on Prices

One of the changes that was made with the refinement of the WooCommerce Settings in WooCommerce 2.1 was the removal of the option to show trailing zeros after prices.

Pre WooCommerce 2.1 there was a checkbox you could check to show the prices with trailing zeros, this was removed and replaced with a filter instead.

In order to display trailing zeros on your prices add the code below to your theme’s functions.php file

WooCommerce 2.1 Variation Prices Revert To 2.0 Format — February 13, 2014

WooCommerce 2.1 Variation Prices Revert To 2.0 Format

WooCommerce 2.1 change price range to WooCommerce 2.0 From priceWith WooCommerce 2.1 just being released a couple of days ago, a lot of users may have noticed a couple of big changes to the plugin, like a refined settings section and the introduction of an all new REST API.

The aim with each major WooCommerce release is to simplify and make it faster and more scalable, and with WooCommerce 2.1 this meant that a lot of the setting that was rarely uses was removed and a few formatting changes was made based on customer feedback.

One of the formatting changes that was made was to remove the “From: $x” price formatting of variation products in favor of a range ie “$x – $y”. This new range format for variable product may not appeal to everyone and that is where the following snippet comes into play.

The code snippet will change the new range price format back to the “From:” price format that users are accustomed to in WooCommerce 2.0.

To revert your WooCommerce variation prices back to the “From:” price format add the following code to your theme’s functions.php file

%d bloggers like this: