【问题标题】:Wordpress output message [closed]Wordpress 输出消息 [关闭]
【发布时间】:2016-01-26 20:25:59
【问题描述】:

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

heres the code

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

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 = 数组();

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

}

【问题讨论】:

  • 请将代码添加为格式化的纯文本。
  • JPEG 格式的代码不是很有帮助...
  • 我的坏...现在编辑:)
  • 您的意思是文本“>....”应该显示在按钮 Vis handlekurv 之前吗?
  • 是的 :) 尝试更改 $ added_text 中的位置,但没有成功。

标签: php html css wordpress


【解决方案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 ) );

【讨论】:

  • 非常感谢!成功了:)
  • 有人可以帮我解决以下问题吗?我想在“%s 已添加到您的购物车”周围放置一个 div 标签。所以我可以在css中编辑它。试图把它放在文本周围,但输出当然是纯文本:P
  • 能否请您发布更新的代码和预期的输出?
  • 用“问题#2”编辑希望它可以理解:)
  • 让我知道问题 #2 的更新答案是否有效?
猜你喜欢
  • 1970-01-01
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-24
  • 1970-01-01
  • 2015-12-05
相关资源
最近更新 更多