php WooCommerce隐藏添加到购物车时的项目数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WooCommerce隐藏添加到购物车时的项目数相关的知识,希望对你有一定的参考价值。

<?php //<~ don't add me


add_filter( 'wc_add_to_cart_message_html','wb_custom_add_to_cart_message', 10, 2 );
/**
 * Hide number of items added as to message when added to cart.
 *
 */
function wb_custom_add_to_cart_message( $message, $products ) {
	$titles = array();
	$count  = 0;
	$show_qty = false;

	if ( ! is_array( $products ) ) {
		$products = array( $products => 1 );
		$show_qty = false;
	}

	if ( ! $show_qty ) {
		$products = array_fill_keys( array_keys( $products ), 1 );
	}

	foreach ( $products as $product_id => $qty ) { // diff in loop, ternary operator removed
		$titles[] =  sprintf( _x( '&ldquo;%s&rdquo;', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) );
		$count += $qty;
	}

	$titles     = array_filter( $titles );
	$added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', $count, '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', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) );
		$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 ) );
	}


	return $message;

}

以上是关于php WooCommerce隐藏添加到购物车时的项目数的主要内容,如果未能解决你的问题,请参考以下文章

在 Woocommerce 中隐藏已添加到购物车的消息

隐藏产品价格并禁用 Woocommerce 中特定产品类别的添加到购物车

在 Woocommerce 上添加单个产品订阅时的付款问题

php 活动门票加 - 当WooCommerce Ticket添加到购物车时,将其他WooCommerce产品添加到购物车

php 活动门票加 - 当WooCommerce Ticket添加到购物车时,将其他WooCommerce产品添加到购物车

php woocommerce自定义添加到购物车