Wordpress 输出消息 [英] Wordpress output message

查看:29
本文介绍了Wordpress 输出消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要按钮前的文字,有人知道吗?

代码在这里

函数 wc_add_to_cart_message( $product_id ) {$titles = array();

function wc_add_to_cart_message( $product_id ) { $titles = array();

if ( is_array( $product_id ) ) {
    foreach ( $product_id as $id ) {
        $titles[] = get_the_title( $id );
    }
} else {
    $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 ) );

// Output success messages
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
    $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', esc_url( $return_to ), esc_html__( 'Continue Shopping', 'woocommerce' ), esc_html( $added_text ) );
} else {

    $message   = sprintf( '<a href="%s" class="button wc-forward">%s</a>%s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View Cart', 'woocommerce' ), esc_html( $added_text ) );
}

wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );

}

问题 2

函数 wc_add_to_cart_message( $product_id ) {$titles = array();

function wc_add_to_cart_message( $product_id ) { $titles = array();

if ( is_array( $product_id ) ) {
    foreach ( $product_id as $id ) {
        $titles[] = get_the_title( $id );
    }
} else {
    $titles[] = get_the_title( $product_id );
}

$titles     = array_filter( $titles );
$added_text = sprintf( _n( '**DIV HERE** %s has been added to your cart.', '**DIV HERE** %s have been added to your cart.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );


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

wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );

}

推荐答案

这应该有效.试试这个

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

wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );

问题 #2 答案

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

wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );

这篇关于Wordpress 输出消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆