• Resolved álvaro Franz

    (@alvarofranz)


    In Woocommerce, in the single product view somewhere before the “Add to cart” button, I want to enable a checkbox to “Mark as a gift”.

    Then in the Cart view, I want to append to the title the string “Product title – (Gift)”

    When the shop owner gets the order, somewhere there must be a note saying: “This product was marked as a gift”.

    I am currently doing this:

    add_action('woocommerce_before_add_to_cart_quantity', 'afz_is_this_gift_add_cart', 35);
    function afz_is_this_gift_add_cart(){
        ?>
        <p>
        <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><?php _e('This is a gift','afz-woocommerce-gift-checkbox'); ?></span>
        </label>
        </p>
        <?php
    }

    An then before the checkout form:

    add_action('woocommerce_before_checkout_form', 'afz_gift_checkout');
    function afz_gift_checkout(){
        
       $itsagift = false;
        
       foreach(WC()->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', 'afz_change_ship_different_address_text');
       }
        
    }

    But I don’t know how to pass on the ‘It’s a gift” flag into the database so that the shop owner can see what’s going on with this product in the order.

    What do you suggest?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add “gift mode” to product’ is closed to new replies.