One of my businesses is very popular around festive times such as Christmas. This year, I wanted to add the option for customers to gift wrap their purchase which not only will save them time but also increase my AOV (Average Order Value).

As you would have seen, I am keen to where possible use code rather than plugins to achieve certain things. This was one of them!

I wanted to offer UK customers the ability to gift wrap their purchase whilst keeping shipping charges affordable.

To achieve what I wanted, I searched for quite a while and found an old post on Stack Overflow which I ended up forking to get working how I needed it to and you can see the final result below.

screenshot of woocommerce order summary including gift bag option

Before you start making changes, please ensure that you backup your website.

To make it easier to follow, I am going to break it down into sections:

Create the Gift Bag section on your Checkout order summary

The code below goes in your functions.php file and if you simply copy and paste it without following any of the other steps, the conditions applied to this section are as follow:

  • The gift bag section will only show for users who have a UK billing address
  • The gift bag section will not show if there are more than 1 items in the basket
  • The gift bag fee is of £2 which will be added to your basket when you check the box
  • There will be no info icon shown

Change the number of items in cart threshold

If you want to change the number of items for which you hide the Gift Bag section from, you can change the number shown in this bit of code

$threshold = 2; //threshold for showing option

The above means that any basket with more than 1 item, does not show the Gift Bag section.

Change or remove the country restriction

If you only want to present this section to users in a specific country, then you will need to change this bit of code

if ( $current < $threshold && WC()->customer->get_billing_country() == 'GB')

The above code means that if the current basket items number is less than the threshold set above and the customer billing country is United Kingdom (GB) then show. You can use this country code list I collated to help you find the two letter code for the country of choice.

To remove the country restriction completely, you will need to delete this bit of code

$billing_country = WC()->customer->get_billing_country();

And your if statement will need to be changed to this instead

if ( $current < $threshold )

Change how much to charge

To change how much your Gift Bag fee is, you will need to change this bit of code

$fee_amount = 2;

you can change this to whatever you need it to be and it will simply display in your store currency.

Change the text to show

If instead of Gift Bag you want to call it something else, there’s a couple of places you need to make changes to, the first bit which will also give you the option to change the price of gift wrapping is this bit of code

'label' => __('Gift Bag (£2) '),

The second bit is

$fee_label = sprintf( __( "Gift Bag" ));

this here is what will show in your price breakdown, your thank you page and order edit page in your admin area.

 

Style the Gift Bag text

To style the text, you just need to use some CSS and that goes in your stylesheet.css file and not your functions.php file. In my example, I wanted to change the font weight so I added the below, you can add whatever you need to style the text to your preference

/styles gift bag text/
label.checkbox {
font-weight: 500;
}

 

Include an info icon that displays a pop up when clicked

Now this bit, you will need to download a plugin to assist you in getting what you need. The plugin in question is Popup anything on click, this will allow you to create a pop up which you will call using a shortcode.

This plugin gives you the option to either show an image or text as your pop up trigger. Once, you create a pop up, you just need to copy and replace the shortcode in this bit of code

echo do_shortcode('[popup_anything id="67"]');

if however, you don’t want to display a way for people to find out more about what you are trying to offer then, simply remove the above line of code.

Hopefully this has been helpful, despite it being quite a long one!

Was this post helpful?