• When I add a product to my cart I got a message box saying: “”Product 1″ successfully added to your cart” and then it show a button “view cart”.

    I have seen some WooCommerce stores also having a button with “continue shopping” linking to the shop page in this message box. I don′t know if this was a built-in feature in a previous WooCommerce version, but I can′t find any setting for this anymore.

    So what I am searching for is a code-snippet, that add this to the message box.
    If this is not possible, I want to hear in which file, I can add this manually ??

    https://www.ads-software.com/plugins/woocommerce/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Look for the checkbox at Admin page > WooCommerce > Settings > Products tab > Add to basket section: “Redirect to the basket page after successful addition”:

    not checked = stay on page and show “view cart” button

    checked = go to cart page, show cart and show “Continue shopping” button

    Thread Starter Kasper

    (@kasper98)

    Thank you…
    I have not checked the “Redirect to the basket page after successful addition” because I want them to stay on the product page.

    And then I the ‘Continue shopping” button in the message box beside the view cart.

    This is not a feature in the core WooCommerce.

    To add a new button to the page you would have to make a custom page template and change the JavaScript to show the new button after an add to cart action. Could be quite a project.

    If you’ve seen a WooCommerce store with this feature, its possible to look at the page source to find out what theme its based on.

    Thread Starter Kasper

    (@kasper98)

    Alright! Thank you! ??
    Could you tell me in which template or file I can edit this?

    I found this in a file called wc-cart-functions.php:

    /**
     * Add to cart messages.
     *
     * @access public
     * @param int|array $product_id
     * @return void
     */
    function wc_add_to_cart_message( $product_id ) {
    
    	if ( is_array( $product_id ) ) {
    
    		$titles = array();
    
    		foreach ( $product_id as $id ) {
    			$titles[] = get_the_title( $id );
    		}
    
    		$added_text = sprintf( __( 'Added "%s" to your cart.', 'woocommerce' ), join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( join( '", "', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) );
    
    	} else {
    		$added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
    	}
    
    	// Output success messages
    	if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
    
    		$return_to 	= apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
    
    		$message 	= sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
    
    	else :
    
    		$message 	= sprintf('<a href="%s" class="button wc-forward">%s</a> %s', get_permalink( wc_get_page_id( 'cart' ) ), __( 'View Cart', 'woocommerce' ), $added_text );
    
    	endif;
    
    	wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );
    }

    But this is for the other message box on the cart page? The one it use if I check the “Redirect to the basket page after successful addition” setting

    I think its this one:
    templates/single-product/product-thumbnails.php

    You will also need to modify the JavaScript if you want to show the button only after the user adds it to the cart.

    Thread Starter Kasper

    (@kasper98)

    Should that file with product-thumbnails for the single-product include anything for the message box saying: “”Product 1″ successfully added to your cart” ?
    I can′t find anything in that file which look like that ??

    That message comes from the JavaScript which is running in the user’s browser. When the user clicks “Add to basket” the page does not reload. The JavaScript communicates the action to the back end and then produces the “View basket” link. You will need to add code to the JavaScript, or produce a new JavaScript, to make it show the new button. Altering the JavaScript may be necessary after each WC update.

    ericbakuladavis

    (@ericbakuladavis)

    Kasper,

    I’m interested in doing the exact same thing you described. Did you make any progress with that?

    Hi there,

    I have just investigated how to add a “Continue shopping” button in the cart. I found a plugin which did not precisely what I wanted, as it placed a “Continue shopping” button in the product once you’ve added that to the cart. Maybe that will be an idea for you? That plugin is WooCommerce Direct Checkout.

    When you want to add a “Continue shopping” button to the cart, you can change the template for cart.php (plugins\woocommerce\templates\cart\cart.php) as follows:

    Look for line 126:

    <input type="submit" class="button" name="update_cart" value="<?php _e( 'Update Cart', 'woocommerce' ); ?>" />

    Just right before this line (or after, whatever you wish), add the following code:

    <a class="button wc-backward" href="<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>"><?php _e( 'Continue Shopping', 'woocommerce' ) ?></a>

    Personally I think that WooCommerce should build this into their core files! The tricky thing about changing the core files yourself is that you will have to keep in mind that each time you update the WooCommerce version, you will have to update this file as well… ??

    Maybe this will be of help to you!?

    Good luck,
    Monique

    Hi Monique

    Thanks for your reply. The plugin you mentioned sounds like it does exactly what Kasper was wanting.

    Another potential solution is to manually add a “Return to Shop” or “Continue Shopping” button to the top of every product page. That way, the user can use the button, even if he/she doesn’t click “Add to Cart”.

    For anyone that doesn’t already know, here are some ways to make WooCommerce updates easier: This short and sweet article explains how to modify your WooCommerce core files without loosing your changes during an update.

    As Monique and the article point out, you will still want to update your customized files whenever WooCommerce updates the file you are overriding. To make this easier, I suggest putting a comment at the top of each of your customized files, referencing the line number on which your custom code appears. That way, you can easily find, copy, and paste your code into the new version of the file and then put the new custom file in the your-theme/woocommerce/ directory (and hope that it works with the new update!).

    Hi there,
    I’ve a got a little different problem: my “continue shopping” button redirects to the product page just added, instead to the shop page.

    How can I change this?

    I found that “wc-cart-functions.php” and “class-wc-cart.php” files contains pieces of code which implies the forward button with this link: <a href="%s" class="button wc-forward">%s</a> %s'

    Entirely (from wc-cart-functions.php) is:

    // Output success messages
    	if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
    
    		$return_to 	= apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
    
    		$message 	= sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
    
    	else :
    
    		$message 	= sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_page_permalink( 'cart' ), __( 'View Cart', 'woocommerce' ), $added_text );
    
    	endif;
    
    	wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );
    }

    A second problem is that, when trying to edit this file, the “wc-cart-functions.php” is said to be “inactive”…

    Thanks in advance.

    Ok sorry.. I found this that might solve my problem.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘WooCommerce continue shopping in message box’ is closed to new replies.