Wordpress输出消息

时间:2016-01-26 20:26:00

标签: php html css wordpress

I want the text before the button, does anyone one how?

heres the code

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

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 ) );

}

1 个答案:

答案 0 :(得分:1)

这应该有效。试试这个

// 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 ) );