How to remove or re-position add to cart message

I am trying to re-position the Woocommerce message

“X Product” HAS BEEN ADDED TO YOUR CART.

Read More

But with no success. I tried with the hooks like these

remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
add_action( 'woocommerce_before_single_product_summary', 'wc_print_notices', 10 );

The above did not work at all.

Any suggestion will be appreciated.

Edit

I also tried to call the template tag directly in the content-single-product.php file somewhere at the bottom like this

<?php wc_print_notices(); ?>

Still no message shows at the desired place.

<div class="summary entry-summary">

<?php
/**
* woocommerce_single_product_summary hook.
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
do_action( 'woocommerce_single_product_summary' );
?>

</div><!-- .summary -->

<php wc_print_notices();?>

Related posts

2 comments

  1. To remove it you could just hide it with CSS:

    .woocommerce-message, .woocommerce-info { display:none; }
    

    Or to reposition:

    //Remove Message:
    remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
    
    //Show message call this function where you want the message displayed
    woocommerce_show_messages();
    
  2.     //Might be a very late but to people looking still you could try these.
        remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
        add_action('woocommerce_before_single_product','your_function_name');
        function your_function_name(){
         //your code here 
        
        }
    
        //Here is the template that returns the output notices 
        //if you want to include in the banner as well
    <div class="woocommerce-notices-wrapper">
              <?php     wc_print_notices(); ?>
          </div>
    

Comments are closed.