【发布时间】:2021-12-06 13:44:31
【问题描述】:
我正在使用下面的这个 sn-p 来稍微修改 Woocommerce 的添加到购物车消息。它从产品页面重定向到购物车页面。我想将产品的缩略图添加到该 Woocommerce 消息通知中,以便向客户更清楚地显示已添加到购物车的内容。有什么解决办法吗?我尝试了很多不同的方法,但都没有成功。
function ace_add_to_cart_message_html( $message, $products ) {
$count = 0;
$titles = array();
foreach ( $products as $product_id => $qty ) {
$titles[] = ( $qty > 1 ? absint( $qty ) . ' × ' : '' ) . sprintf( _x( '“%s”', '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.', // Singular
'%s are added to your cart.', // Plural
$count, // Number of products added
'woocommerce' // Textdomain
), wc_format_list_of_items( $titles ) );
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_checkout_url() ), esc_html__( 'Proceed to checkout', 'woocommerce' ), esc_html( $added_text ) );
return $message;
}
【问题讨论】:
标签: woocommerce