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

前端 未结 6 875
感情败类
感情败类 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:47

    Have you tried a filter like the following

    function your_add_to_cart_message() {
    if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
        $message = sprintf( '%s%s', __( 'Successfully added to cart.', 'woocommerce' ), esc_url( get_permalink( woocommerce_get_page_id( 'shop' ) ) ), __( 'Continue Shopping', 'woocommerce' ) );
    else :
        $message = sprintf( '%s%s', __( 'Successfully added to cart.' , 'woocommerce' ), esc_url( get_permalink( woocommerce_get_page_id( 'cart' ) ) ), __( 'View Cart', 'woocommerce' ) );
    endif;
    return $message;
    }
    add_filter( 'wc_add_to_cart_message', 'your_add_to_cart_message' );
    

    In reply to the ajax message update, try a translation function like:

    function your_woo_ajax_solution( $translation, $text, $domain ) {
      if ( $domain == 'woocommerce' ) { // your domain name
        if ( $text == 'View Cart' ) { // current text that shows
            $translation = 'Basket updated.'; // The text that you would like to show
        }
      }
    
      return $translation;
    }
    add_filter( 'gettext', 'your_woo_ajax_solution', 10, 3 );
    

提交回复
热议问题