• Resolved wheelmuc1

    (@wheelmuc1)


    Hi together,

    I implemented an auto add function in woocommerce that adds a cleaning fix fee to a wheelchair rental.
    Now I would like the quantity counter and the removal field to be removed so that the customer cannot remove the fee from the basket.


    therefore i umplemented the following function in my functions.php:

    add_filter('woocommerce_cart_item_remove_link', 'customized_cart_item_remove_link', 20, 2 );
    function customized_cart_item_remove_link( $button_link, $cart_item_key ){
        $targeted_products_ids = array( 150);
    
        $cart_item = WC()->cart->get_cart()[$cart_item_key];
    
        if( in_array($cart_item['data']->get_id(), $targeted_products_ids) )
            $button_link = '';
    
        return $button_link;
    }

    Here I adjusted the targeted products_ids array to only apply this on the cleaning fee product.

    Unfortunately this does not work and the remove link is still available.
    Also I was wondering if there is any possibility to remove the quantity switcher.

    Many thanks for your support.

    Greetings

    Andreas

    • This topic was modified 8 months, 2 weeks ago by wheelmuc1.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @wheelmuc1,

    The code snippet you’ve shared seems to be correctly structured. However, the issue might be with the product ID. Please confirm that 150 is the correct ID for the cleaning fee product.

    For the quantity selector, you can use the woocommerce_is_sold_individually filter.

    If you continue to face issues, I recommend using our WooCommerce Product Add-Ons extension. This extension allows you to add additional paid services (like a cleaning fee) to your products. It also provides an option to make the add-on mandatory, thus preventing customers from removing it from their carts.

    You can also use the Extra Fees for WooCommerce or Extra Fees Plugin for WooCommerce. This plugin allows you to charge additional fees based on product price, payment gateway, and cart subtotal.

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thread Starter wheelmuc1

    (@wheelmuc1)

    Hi there,

    many thanks for your support.

    I can confirm that the product id of the cleaning fee is correct.

    Also i tried to implement the removal of the quantity selector by adding

    function wc_remove_quantity_field_from_cart( $return, $product ) { if ( is_cart() ) return true;}

    add_filter( ‘woocommerce_is_sold_individually’, ‘wc_remove_quantity_field_from_cart’, 10, 2 );

    to my childs theme functions php file.

    Unfortunately this does not affect the selector at all.
    I am using the latest woocommerce version. Can it be that this function is already deprecated ?

    Greetings

    Andreas

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @wheelmuc1,

    The code you shared for removing the quantity selector should work correctly. Are you using block or shortcode on the cart page?

    I have tried the code snippet shared here with Storefront theme, and looks working fine.

    Let us know how that goes. Looking forward to helping you.

    Thread Starter wheelmuc1

    (@wheelmuc1)

    Hi Shameem,

    thank you so much for your help. Actually changing the basket from block mode to shortcode solved the problem.
    Now the functions are working fine ??
    The layout is not that apealing anymore but it works.
    So I’ll try to figure out how to achieve a better layout with the shortcode mode.

    Greetings

    Andreas

    Plugin Support omarfpg a11n

    (@omarfpg)

    Hi Andreas @wheelmuc1,

    Thank you so much for confirming this has solved your problem!

    We could also look at this one from another perspective… Have you considered adding your fee not as a product but as an actual fee? There are plugins and even code snippets to achieve this, too! A quick Google search can give you plenty of options! ??

    I hope this helps so far!
    -OP

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Prevent Customer form removing auto add product in basket’ is closed to new replies.