I came across a project recently that needed to offer a variety of products that offered free shipping, while other products in their WooCommerce store needed to have a shipping cost associated with them. This can be a bit tricky, and one of the simplest solutions is to simply mark any products that you want to have free shipping as a ‘Virtual Product’.
WooCommerce is intuitive enough to know that typically a ‘virtual product’ would not need to be shipped, as it isn’t a tangible item, so they automatically remove the option to select a separate shipping address during checkout. In my case it was a tangible item so the user needed to keep the option for a shipping address. This brief tutorial will show you how to do that.
Add Shipping Option Back to Checkout Page
The first thing we need to do is add the option for a shipping address back to the checkout page. There are plenty of tutorials out there for this – simply add the following to your functions.php file:
<?php add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
This will add the option to select a separate shipping address during checkout. Simple enough, right? Is that all there is to it? Almost, but not quite.
Unfortunately, even though we have added this back to the checkout page, the information is still NOT included in the New Order notification that is sent out to the admin when a purchase is made. The information IS stored and can be looked up in the WordPress dashboard, but it really should be included in the email as well.
Add Shipping Information to New Order Notification
Disclaimer: the store I use this technique on is very small and this method is not tested thoroughly is a larger WooCommerce store environment!
To add the shipping information to the new order email we need to copy /templates/email/email-addresses.php from the WooCommerce plugin to your /woocommerce/emails folder in your theme or child theme. If you do not have a woocommerce folder in your theme or child theme, simply create one. Files in that folder will override the default WooCommerce files, as long as the structure is correct. As a side note, make sure you DO NOT edit core files in any plugins directly. You should always make changes in a child theme to ensure your changes are not overwritten if the plugin has an update.
In that file we need to make one change on line 26:
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) ) : ?>
<?php if ( ! wc_ship_to_billing_address_only() && ( $shipping = $order->get_formatted_shipping_address() ) ) : ?>
You’ll see we have removed a small part of the if statement that references the needs_shipping_address() function. By removing this, the shipping address is now included in the New Order email that is sent to admins after a new purchase from your WooCommerce Store.