Gift Checkbox at Single Product Page WooCommerce

In WooCommerce, many customer want to send a gift to their friends but there are confused about Shipping to a different address in checkout page. So here we will provide a solution.

We display checkbox on single product page called “Is this a gift?”. If it is checked that means gift is in cart so we will renaming “Shipping to a different address” into “Who is this gift for?”. So customer doesn’t get confused about their product and shipping address.

So here is code. Add below line of code in your theme’s functions.php file of your active child theme (or theme) and save the file.

// Display Gift checkbox 

add_action( 'woocommerce_before_add_to_cart_quantity', 'display_gift_checkbox', 35 );
  
function display_gift_checkbox() {
         
        ?>
 
        

cart->get_cart() as $cart_item_key => $cart_item ) { if ( isset( $cart_item['is-gift'] ) ) { $itsagift = true; break; } } if ( $itsagift == true ) { add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' ); add_filter( 'gettext', 'translate_shipping_gift' ); } } function translate_shipping_gift( $translated ) { $translated = str_ireplace( 'Ship to a different address?', 'Who is this Gift For?', $translated ); return $translated; }

Leave a Comment

Scroll to Top