Change Added to Cart Message for Specific Products on One Page Only?
-
I’m trying to change the added to cart message on one page only by adding a bit of code to the functions.php in my child theme. The following code works fine to change the added to cart message for specific products:
add_filter( 'wc_add_to_cart_message', 'add_to_cart_change', 10, 2 ); function add_to_cart_change($message, $product_id) { global $woocommerce; $gotostep = 0; $products = array(1=>array(2679,2680,2681,2682)); foreach ($products as $key=>$value) { if (in_array($product_id, $value)) { $gotostep = $key + 1; } } if ( $gotostep != 0 ) { $message = __('Product successfully added to your cart.', 'woocommerce') . ' <a href="' . $gotostep . '" class="real-amp-step-link">Go to Step ' . $gotostep . '</a>'; } return $message; }
I want to add is_page() in there somewhere to limit it only to one page; however, is_page() always returns false if I put it in the function, or wrap the add_filter in a conditional.
I tried putting is_page() into wp_enqueue_scripts, where it returns true, and then calling:
add_filter( 'wc_add_to_cart_message', 'add_to_cart_change', 10, 2 );
but it didn’t work either.
How would I use is_page() to conditionally change the added to cart message?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Change Added to Cart Message for Specific Products on One Page Only?’ is closed to new replies.