• Resolved graybag

    (@graybag)


    Hi,

    is there any way to hide the option to add to add gift wrap if it’s already in the basket? So I’m thinking of having it on the cart page, and if it’s not added to the cart it will show on the checkout page.

    Or vice versa, if they add it at the cart, the button wont show on the checkout.

    Thanks
    Graham

Viewing 2 replies - 1 through 2 (of 2 total)
  • What about something like this:

    function hide_prompt_if_wrap_in_cart() {
    
        if ( is_admin() ) return; // only run front end
        if ( ! class_exists( 'WC_Gift_Wrapper' ) && ! class_exists( 'woocommerce' ) ) return; // some simple checks for required plugins
    
        if ( WC_Gift_Wrap()->wrapping->giftwrap_in_cart == true ) { // there is wrap in the cart
            remove_action( 'woocommerce_before_checkout_form', array( WC_Gift_Wrap()->wrapping, 'before_checkout_form' ) ); // unhook unwanted prompts when wrap in cart
    	remove_action( 'woocommerce_after_checkout_form', array( WC_Gift_Wrap()->wrapping, 'after_checkout_form' ) ); // unhook unwanted prompts when wrap in cart
        }
    }
    add_action( 'woocommerce_cart_loaded_from_session', 'hide_prompt_if_wrap_in_cart', 20 );

    You can add this code to your child theme’s functions.php file or by using the Code Snippets plugin (frontend loading only).

    Thread Starter graybag

    (@graybag)

    Works a treat, thanks so much. Super plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide option if in basket’ is closed to new replies.