0
私のウェブサイトには2つの製品があり、異なる商品をカートに追加する際に、異なるメッセージ(HTMLを使用したいというメッセージで)を表示します。今すぐ表示されますProduct successfully added to cart.
私の子供のfunction.phpでこのコードを使用していますが、私が正確に望むものを教えてくれません。それが今は非推奨だとWooCommerce 3 wc_add_to_cart_message
がwc_add_to_cart_message_html
に置き換えられているのでWooCommerce 3の製品IDに基づいてカートに追加メッセージをカスタマイズする
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'));
return $message;
}
商品のいずれかがカートに追加された場合、「あなたの商品がカートに追加され、「カートを見る」」というメッセージが表示されます。カートにp1を追加すると「message1」が表示され、カートにp2を追加すると「message2」が表示されるような、別の製品を追加するためのさまざまなメッセージを表示したい私は今、それが意味をなさないことを願っています。 –