Home Forums WoodMart support forum Already added to Cart

Already added to Cart

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #207078

    afarahani
    Participant

    Hi,
    It seems the theme lacks the feature that when a single product is already added to the cart, it tells the visitor it is already in the cart by changing the icon or button text and deactivating the “Ad to Cart” button. Instead, it allows clicking on the “add to cart” button if in the shop and takes the user to product page (for single product) and then shows a message that this is already in the cart.

    Same situation with product page “add to cart” button. When the product is added to the cart, still doesnt know the product is already selected because the button still allows selecting the prodcut.

    Can you please provide a fix for this?

    #207097

    afarahani
    Participant

    TO meet you in the middle, I added the following code to change the text when the product is already in the cart. Please let me have a code to deactivate click function on the cart button in shop and product page when it is already in the cart.

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'bbloomer_custom_add_cart_button_single_product' );
     
    function bbloomer_custom_add_cart_button_single_product( $label ) {
        
       foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
          $product = $values['data'];
          if( get_the_ID() == $product->get_id() ) {
             $label = __('Already in your list', 'woocommerce');
          }
       }
        
       return $label;
     
    }
     
    // Part 2
    // Edit Loop Pages Add to Cart
     
    add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_custom_add_cart_button_loop', 99, 2 );
     
    function bbloomer_custom_add_cart_button_loop( $label, $product ) {
        
       if ( $product->get_type() == 'simple' && $product->is_purchasable() && $product->is_in_stock() ) {
           
          foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
             $_product = $values['data'];
             if( get_the_ID() == $_product->get_id() ) {
                $label = __('Already in your list', 'woocommerce');
             }
          }
           
       }
        
       return $label;
        
    }
    #207170

    Eric Watson
    Participant

    Hello,

    Could you please check how it works with some default WordPress themes like TwentyTwenty or WooCommerce Storefront to understand is it our theme issue or not?

    Regards

    #207359

    afarahani
    Participant

    It works perfectly fine with Woodmart, but I have not tested it with any other theme. The only thing that is missing is to dissable the click and hover functions of button when the individual item (for exmple for downloadable prodcut) is already in the cart.

    #207360

    afarahani
    Participant

    Would you help with that part?

    #207467

    Artem Temos
    Keymaster

    Hello,

    Sorry, but such additional code customizations are out of our theme support scope.

    Thank you for understanding.

    Kind Regards

    #207479

    afarahani
    Participant

    Yeah! I am sorry too that such feature is also not already part of the theme.

    #207482

    Artem Temos
    Keymaster

    No problem, contact us if you will have any questions.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Already added to Cart’ is closed to new replies.