Adding Shipping Insurance in WooCommerce

Written by Sean Flannigan

shipping insurance in woocommerce broken plate

Let’s talk about offering optional shipping insurance in WooCommerce for your customers.

Shipping Insurance in WooCommerce

Shipping insurance is an optional feature you can add to WooCommerce. This insurance can be used to replace items that are damaged or lost during the shipping process.

There is no core option for setting up shipping insurance, but developers have created workarounds to make this possible!

Hidden Product Workaround

The first thing you’ll want to do is set up a product which will be associated with shipping insurance.

You can call this product “Shipping Insurance”, or whatever else you would like. Update the product’s visibility to “hidden” so that it doesn’t appear in your catalog or search results.

You’ll also set the price for shipping insurance in the product details area.

Take note of the product ID of your new product – this can be found on the All Product screen when you hover over the product.

Once your product has been created, you’ll need to update your functions.php file with some custom code.

We highly recommend installing a plugin that will manage any custom code rather than modifying functions.php directly. It is not recommended to modify the PHP file directly. In the video, we use the plugin Code Snippets.

Adding Custom Code to Functions.php

Custom code can be found at this excellent post on Stack Exchange. Here is the code from that post:

add_action(‘woocommerce_cart_totals_after_shipping’, ‘wc_shipping_insurance_note_after_cart’);
function wc_shipping_insurance_note_after_cart() {
global $woocommerce;
$product_id = 669;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values[‘data’];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found ):
?>
<tr class=”shipping”>
<th><?php _e( ‘Shipping Insurance’, ‘woocommerce’ ); ?></th>
<td><a href=”<?php echo do_shortcode(‘[add_to_cart_url id=”669″]’); ?>”><?php _e( ‘Add shipping insurance (+$3)’ ); ?> </a></td>
</tr>
<?php else: ?>
<tr class=”shipping”>
<th><?php _e( ‘Shipping Insurance’, ‘woocommerce’ ); ?></th>
<td>$3</td>
</tr>
<?php endif;
}

Make sure you add in the correct product ID for your hidden product, as well as the desired text you’d like your customer to see with the cost of the insurance.

Once the custom code is added to your functions.php file, customers will see the option to add shipping insurance once products are in their cart. 

Find our other WooCommerce tutorials here. Find out all about our amazing WooCommerce expertise here.

WooCommerce,Tutorial

   

Let’s Get In Touch

Our team would love to talk with you about your goals for your business and how our experienced developers and designers can help you achieve those goals. Whether you have a simple question or a complex upcoming project, please don’t hesitate to reach out.

  • We'll be in contact soon!
  • This field is for validation purposes and should be left unchanged.