小编Jas*_*ngh的帖子

根据 WooCommerce 3 中的产品 ID 自定义添加到购物车的消息

我的网站上有两种产品,想要在将不同产品添加到购物车时显示不同的消息(在消息中我想使用 HTML)。现在它显示Product successfully added to cart. 我正在我孩子的 function.php 中使用此代码,该代码正在运行,但没有给我我真正想要的东西。

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 successfully added to your Basket.', '%s have been added to your Basket.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );

$message = sprintf( '%s <a href="%s" class="button">%s</a>',
               esc_html( $added_text ),
               esc_url( wc_get_page_permalink( 'cart' ) ),
               esc_html__( 'View Cart', 'woocommerce' …
Run Code Online (Sandbox Code Playgroud)

php wordpress product messages woocommerce

0
推荐指数
1
解决办法
4576
查看次数

标签 统计

messages ×1

php ×1

product ×1

woocommerce ×1

wordpress ×1