Woocommerce, How to edit the “added to cart” message

前端 未结 6 869
感情败类
感情败类 2021-02-08 11:02

When click on add to cart button, the Woocommerce shows the message, view cart, I want to edit this message, actually edit all the span, put some icon etc...

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 11:52

    In Woocommerce 3.0 "wc_add_to_cart_message" is obsolete and no longer works. So while the answer by @zmonteca was ok, is no longer working on the Woocommerce 3.0

    Just replace "wc_add_to_cart_message" with "wc_add_to_cart_message_html" and voile... works.

    add_filter ( 'wc_add_to_cart_message', 'wc_add_to_cart_message_filter', 10, 2 );
    function wc_add_to_cart_message_filter($message, $product_id = null) {
    $titles[] = get_the_title( $product_id );
    
    $titles = array_filter( $titles );
    $added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );
    
    $message = sprintf( '%s %s %s',
                    esc_html( $added_text ),
                    esc_url( wc_get_page_permalink( 'checkout' ) ),
                    esc_html__( 'Checkout', 'woocommerce' ),
                    esc_url( wc_get_page_permalink( 'cart' ) ),
                    esc_html__( 'View Cart', 'woocommerce' ));
    
    return $message;}
    

提交回复
热议问题