WooCommerce: “Is This a Gift?” Checkbox @ Single Product Page

A client of mine asked me to code a checkbox on the single product page called “Is this a gift?”. They noticed that their customers who want to gift the product to a friend get confused with the “Shipping to a different address” form in the WooCommerce checkout.

So, what about renaming “Shipping to a different address” into “Who is this gift for?” if a “gift” is in the cart? Well, this snippet does just that and you can adapt it / customize it to your specific case.

“Is this a gift?” checkbox @ WooCommerce single product page

PHP Snippet: “Is This a Gift?” Checkbox @ Single Product Page – WooCommerce

* @snippet       "Is This a Gift?" Checkbox @ Single Product Page - WooCommerce
* @how-to        Get CustomizeWoo.com FREE
* @sourcecode    https://businessbloomer.com/?p=73381
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.1
* @donate $9     https://businessbloomer.com/bloomer-armada/

// -------------------------
// 1. Display Is this a Gift checkbox 
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_is_this_gift_add_cart', 35 );
function bbloomer_is_this_gift_add_cart() {

		<p class="">
		<label class="checkbox">
		<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="is-gift" id="is-gift" value="Yes"><span>Is this a gift?</span>


// -------------------------
// 2. Add the custom field to $cart_item
add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_store_gift', 10, 2 );
function bbloomer_store_gift( $cart_item, $product_id ) {
if( isset( $_POST['is-gift'] ) && $_POST['is-gift'] == "Yes" ) {
	$cart_item['is-gift'] = $_POST['is-gift'];
return $cart_item; 
// -------------------------
// 3. Preserve the custom field in the session
add_filter( 'woocommerce_get_cart_item_from_session', 'bbloomer_get_cart_items_from_session', 10, 2 );
function bbloomer_get_cart_items_from_session( $cart_item, $values ) {
if ( isset( $values['is-gift'] ) ){
	$cart_item['is-gift'] = $values['is-gift'];
return $cart_item;
// -------------------------
// 4. If gift in cart, edit checkout behavior:
// a) open shipping by default
// b) rename shipping title
add_action ( 'woocommerce_before_checkout_form', 'bbloomer_gift_checkout' );

function bbloomer_gift_checkout() {
	$itsagift = false;
	foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
		if ( isset( $cart_item['is-gift'] ) ) {
			$itsagift = true;
	if ( $itsagift == true ) {
		add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' );
		add_filter( 'gettext', 'bbloomer_translate_shipping_gift' );

function bbloomer_translate_shipping_gift( $translated ) {
$translated = str_ireplace( 'Ship to a different address?', 'Who is this Gift For?', $translated );
return $translated;

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

27 thoughts on “WooCommerce: “Is This a Gift?” Checkbox @ Single Product Page

  1. Hey, I just added it to my site, and placed a test order. When i go into my dashboard to review the order im not notified anywhere on the order that its a gift. Am i missing something?

    1. True. But anyhow, shipping and billing addresses will be different, so in that case you’ll know it’s very likely a gift. In case you need to have a special note on the order and identify gift orders, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi Rodolfo. I’ve implemented your code and it all works flawlessly. However, I’m having one issue. The Gift Note custom field is showing on the checkout page even when the gift checkbox is not checked. And it’s always required. If there’s no data in the field I get the “shiny new field” error.

    1. Hi Paul! My snippet adds a custom field to products, not the checkout – and there is no checkout validation for that. Sure that you’re using my snippet?

  3. Hi Rodolfo. Just implemented your code snippet and it works flawlessly through checkout. I’m impressed it automatically displays the alternate shipping address based on it being a gift. The only thing I’m not seeing is where the gift note shows to an admin after the sale transaction is complete so he/she will know it’s a gift and include a note in the shipment.

    1. You’re right, this is not saved to the order. Take a look at part 5 here and you should figure that out: https://businessbloomer.com/woocommerce-add-custom-checkout-field-php/

      1. Hi Rodolfo. In the link above, there is no part 5. Can you tell me if it’s possible to tag an order as a gift for the admin filling orders? I may just be missing something.Thanks for your help. (Note: I did customize the three steps on the page above, but it passes the field info to the order page whether it’s a gift or not).

        1. Sorry, I meant part 3

  4. Suppose, instead this was an extra service price option checkbox. How to add it to the product price.

    1. Hi Ankish, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. I have implemented it to staging version and it worked but I made few changes on the order form. So, I need to update the second form as well.
    I offer Cash on Delivery and Bank Transfer payment options. COD doesn’t make sense with these changes. So, I need to disable the COD when the product item is Gift.

    Thanks, great work.

    1. Muhammad, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  6. I wrote a comment a few mins ago, saying this snippet doesnt work

    my apologies, but it does work

    1. Great!

  7. I just tried this and it didn’t work for me. Is this still working?

  8. Hi Rodolfo,

    I came across this and its exactly the function I needed yet it just didn’t work with Woocommerce subscriptions and variations so I went I bought an add-on, Gifting for Woocommerce Subscriptions, but it doesn’t check the shipping address by default like your function above, is there any way I can use part 4. of your function with my Gifting plugin?

    1. Hello Chris, thanks so much for your comment! Yes, this is possible – I think. Try to use part 4 and see if you manage to make it work ๐Ÿ™‚

  9. Hi There,
    I love this snippet but I have one problem. The majority of my products this works great for but I have a handful of products that I don’t want this to show as an option, I have tried different things and can’t get it to work to exclude this checkbox on those products.

    Could you lead me into the right direction.

    1. Hello Steven, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  10. hi there, i have just tried the code but it doesn’t work here, i can select this is a gift but what it does is select automatically delivery to a different address. Thanks.

    1. Correct Luca, that’s what id does – the gift recipient usually has a different shipping address than the person buying it. Maybe the part that’s not working for you is the translation bit, in case you use WooCommerce in a different language – you’ll need to fix that part ๐Ÿ™‚ Hope this helps

  11. This is a brilliant idea, and was really hoping to utilize it. Unfortunately when I add this snippet to my functions.php in my child theme as described above, the entire site is crashed and won’t load. So I tried putting it in my style.css file, and no change was observed. Is this happening for anyone else?

    1. Hey Mike, I just retested it and it works. It goes into functions.php. Try to debug your PHP errors here: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

  12. Thanks Rodolfo, it’s a great snippet and I’ve also integrated it with the “add fee to cart” snippet you mentioned. All is ok. The only one thing to add to be perfect concern to cart page. In effect, when I select “Is this a gift?” checkbox on product page and then I go to cart page, we have no more way of remove the option if I change my mind. It would be cool adding a checkbox option just below the product(s) in cart page so the customer can decide if hold the gift option or remove it. Is it possible? and…how? Thanks again and..sorry for my English. Greetings from Italy.

    1. Fabrizio, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  13. This would be perfect if you could set a price for gift wrapping too.

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *