Display Message on Cart Page for Specific Products Only
-
Hi there,
I want to add a message on the cart / basket page for specific products only.
I used the code below but the message displays for all products instead of just the three that its indented for: 672, 667, 260.
add_action( 'woocommerce_cart_totals_before_shipping', 'twg_add_checkout_message', 12 ); function twg_add_checkout_message() { // set your products IDs here: $product_ids = array( 672, 667, 260 ); $bool = false; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $item = $cart_item['data']; if ( in_array( $item->id, $product_ids ) ) $bool = true; } // If the special cat is detected in one items of the cart // It displays the message if ($bool) echo '<div class="vouchers_checkout_message">'; echo '<h3>How can I get my voucher before Christmas?</h3>'; echo '<p>Royal Mail are currently experiencing long delays, so if you need your voucher to arrive <strong>before Christmas</strong>, we suggest <strong>upgrading to the £4.99 DHL</strong> option which is delivered the next working day after dispatch. Our last shipping date with DHL is <strong>22nd December</strong>.</p>'; echo '</div>'; }
Please help, or is there better solution to the snippet above.
Many thanks
Warren
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Display Message on Cart Page for Specific Products Only’ is closed to new replies.