简体   繁体   中英

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

在此处输入图像描述

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.

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.

如果您想更改wc-cart-functions.php文件并想返回带有View Cart按钮的继续购物按钮,只需在if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) )条件的else部分中编写代码下面给出了wc-cart-functions.php文件。

$message   .= sprintf( '<a href="%s" class="button wc-forward">%s</a>', esc_url( wc_get_page_permalink( 'shop' ) ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) );

@Jan Novak For me the function sort of works; it displays the button. I've changed 'shop' in wc_get_page_permalink( 'shop' ) to the name of my shop page. The problem is that instead of the shop permalink it returns the product page permalink/url. Something I'm not getting here.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM