• Resolved sunitasinghdev

    (@sunitasinghdev)


    Hello, I am trying to Hide or Remove Terms & Conditions checkbox from checkout page for a specific product, not for all products. Here is the link, https://magicbookofrecord.com/stores/checkout/?add-to-cart=9918&quantity=1

    I am trying below code, but it’s working for privacy policy, this code not working for terms and conditions checkbox.

    add_action('woocommerce_checkout_init', 'disable_checkout_terms_and_conditions', 10 );
    function disable_checkout_terms_and_conditions(){
    	// Product ID to hide fields for
        $target_product_id = 9918; // Replace with the actual product ID
        // Get available payment gateways
       foreach( WC()->cart->get_cart() as $cart_item ) {
        
        if( $cart_item['data']->get_id() == $target_product_id )  {
            remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
            remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
        }
    }
    }
    

    Please help me from this issue .

Viewing 7 replies - 1 through 7 (of 7 total)
  • Yes I would expect that to work. Does it work if you temporarily switch to say the 2022 theme? If it does, its possible that your theme has modified the default woocommerce hook. Download your theme onto your hard drive and do a text search for the hook to see if your theme is doing it differently.

    Thread Starter sunitasinghdev

    (@sunitasinghdev)

    add_action('wp_footer', 'hide_payment_section_for_product');function hide_terms_and_conditions_section_for_product() {    // Replace '123' with the actual product ID for which you want to hide the payment section    $product_id = 9918;        // Check if the current product ID matches the specified product    if (is_product() && get_the_ID() == $product_id) {        echo '<style>.woocommerce-terms-and-conditions-wrapper { display:none !important; }</style>';    }}add_action('wp_footer', 'hide_terms_and_conditions_section_for_product');

    I am trying this code in footer.php. it works for all product. It is not working for a specific product. So suggest me where i am wrong

    Your last code appears at the very bottom of the page. It is being interpretted as html, not as php. Any custom functions need to go in functions.php for your child theme.

    is_product() only returns true on a single product page so it will be false on the checkout page.
    https://woocommerce.com/document/conditional-tags/

    get_the_id() returns the current item in the wordpress loop, but there is no wordpress loop on the checkout page. I think you should keep to the code which loops through the cart items:

    foreach( WC()->cart->get_cart() as $cart_item ) {
        if( $cart_item['data']->get_id() == $target_product_id )  {
    

    I think your first code was better, but you need to find the right hook names. Download your theme onto your hard drive and do a text search for the hook to see if your theme is doing it differently.

    Thread Starter sunitasinghdev

    (@sunitasinghdev)

    I tried all hook functions for terms and conditions, still not working

    add_action('woocommerce_checkout_init', 'disable_checkout_terms_and_conditions', 10 );function disable_checkout_terms_and_conditions(){	// Product ID to hide fields for    $target_product_id = 9918; // Replace with the actual product ID    // Get available payment gateways   foreach( WC()->cart->get_cart() as $cart_item ) {        if( $cart_item['data']->get_id() == $target_product_id )  {        remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );        remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );        remove_action( 'woocommerce_checkout_terms_and_conditions', 'woocontracts_terms_fields' ); // <== missing priority        remove_action( 'woocommerce_checkout_after_terms_and_conditions', 'woocontracts_checkout_additional_checkboxes', 10 );    }}}

    Any other options

    OK. I got this to work for me. See how it goes.

      add_action( 'woocommerce_checkout_init', 'disable_checkout_terms_and_conditions', 10 );
      function disable_checkout_terms_and_conditions() {
        // Product ID to hide fields for
        $target_product_id = 9918;
        foreach( WC()->cart->get_cart() as $cart_item ) {
          if( $cart_item['data']->get_id() == $target_product_id ) {
            add_filter( 'woocommerce_checkout_show_terms', '__return_false' );
          }
        }
      }

    Hi @sunitasinghdev

    Thanks for reaching out!

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Removing Terms & Conditions Checkbox for a specific product’ is closed to new replies.