• Resolved Fujyn

    (@arwah12)


    I need help with this problem
    I successfully changed the “add to cart” button on a product that was already in the basket,
    to “Already in the Cart. Add again” on the shop page and one product page
    with this code

    /**
     * @snippet       Change "Add to Cart" Button Label if Product Already @ Cart
     * @how-to        Get CustomizeWoo.com FREE
     * @source        https://businessbloomer.com/?p=73974
     * @author        Rodolfo Melogli
     * @compatible    WC 3.5.4
     * @donate $9     https://businessbloomer.com/bloomer-armada/
     */
     
    // Part 1
    // Edit Single Product Page Add to 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 Cart', '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 Cart', 'woocommerce');
             }
          }
           
       }
        
       return $label;
        
    }

    so the problem is I want to change it when I click “Already in Cart. Add again” then it is immediately transferred to the basket.
    if now I experience, when clicked on “Already in Cart. Add again”
    it just adds more to the basket.
    how to do it, what code should I add again.
    thank

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Already in Cart Add again. Then it goes directly to the basket.’ is closed to new replies.