PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 5, 2022

[FIXED] How to add "Continue Shopping" button next to "View Cart" button in WooCommerce?

 February 05, 2022     hook-woocommerce, php, woocommerce, wordpress     No comments   

Issue

enter image description here

I am working on WooCommerce site, for some reason I want to display "Continue Shopping" button and "View Cart" button together after adding product to the cart. I found the file wc-cart-function.php that says Output success message to show message but I couldn't return view cart and continue shopping's $message variable with single return $message.

Thanks in advance.


Solution

I believe you can do it this way.

function filter_wc_add_to_cart_message_html( $message, $products ) { 

    $return_to = apply_filters( 
        'woocommerce_continue_shopping_redirect', 
        wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) 
    );

    $continue   = sprintf( 
        '<a href="%s" class="button wc-forward">%s</a>', 
        esc_url( $return_to ), 
        esc_html__( 'Continue shopping', 'woocommerce' ) 
    );

    $message .= $continue;
    return $message; 
}; 

add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );

For more details take a look at "wc_add_to_cart_message_html" hook.



Answered By - Jan Novak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing