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
In WooCommerce 2.1 the repeat password fields was removed as it was decided it was easy enough to reset your password with one click should you have gotten in wrong.
If you would still like to add a password confirm field on your register page all you have to do is add the code below to your theme’s functions.php file.
This will add a new field underneath the password field with a label Password Repeat, and then when the customer clicks register it will match the password and password repeat fields against each and and proceed with registration it it matches, or throw an error if it does not match.
<?php
// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts.
The 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
<?php
// place the following code in your theme's functions.php file
// Add a second password field to the checkout page.
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
<?php
// Place in your theme's functions.php file
// Revert grouped product prices to WooCommerce 2.0 format
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
<?php
// Show trailing zeros on prices, default is to hide it.
With 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
/**
* Use WC 2.0 variable price format, now include sale price strikeout
*
* @param string $price
* @param object $product
* @return string
*/
function wc_wc20_variation_price_format( $price, $product ) {
There are some cases where you would like to have you WooCommerce products not display a description, this tutorial will help you achieve just that.
By default WooCommerce has two description fields, a short description and a long description. The short description is usually an excerpt take from the long description unless you enter your own short description on the product page.
The short description is displayed right next to the image on the product page underneath the title, where as the long description is displayed in a tab at the bottom of the product page.
If you would like to either remove the WooCommerce short description or the long description tab, or both, you can do so by adding the following code to your theme’s functions.php file.
<?php
// remove product description from single product pages
Say you operate a WooCommerce store where you sell products that are shipped in boxes but want customers to make up their own boxes with different products, by default WooCommerce will only allow you to sell products in the the quantities you set the product up with and the customer will be able to check out with any amount of items in the cart.
For instance if you operate a online wine store with WooCommerce and would like to sell your wine by the bottle but only want customers to checkout if they have quantities selected that would make up a whole box, the following tutorial is for you.
With the code below you can setup your products that each product is a single bottle of wine and then force the customer to add multiples of any 6 products to the cart before they would be able to checkout. If the customer for example adds only 5 bottles to the cart and then tries to checkout they will be presented with a message to order in multiples of 6.
You can even take it a step further and only allow the rule to apply to products with a certain shipping class, this will allow you to sell single bottles as well as cases without having the multiples rule apply to the case products.
To force the customer to add multiples of a certain quantity to the cart before being able to checkout add the following code to your theme’s functions.php file.
<?php
// check that cart items quantities totals are in multiples of 6
Again WooCommerce does add a lot of information to the emails that goes out to the customers and admin but there are some things that are not part of the emails and another one of those things are the Shipping Method.
The shipping method could useful to display in emails to let shop admin knows how to ship the order if these emails are being used as packaging slips, or to let the customer know what type of shipping they selected at checkout.
To add the shipping method to all WooCommerce emails or just add it to the admin emails add the following code to your theme’s functions.php file.
<?php
// Place the following code in your theme's functions.php file to add the shipping method to all emails
WooCommerce send customers and store admins emails when new orders are placed, these emails contains all sorts of info relating to the order, however it is missing a couple of things that can be useful to customers or store admins.
One of the fields that is not present in the WooCommerce order emails are the payment type, some WooCommerce store admins would perhaps want to know this data in emails for decisions on whether to ship items immediately or to hold off for a while for money to clear.
To add the payment type to all WooCommerce emails or just admin email add the following code to your theme’s functions.php file, this is upgrade safe and the changes will stay in place after WooCommerce updates.
<?php
// Place the following code in your theme's functions.php file to add the payment type to all emails