How do I move the woocommerce error message where I want?

I want to move the woocommerce error inside my section. How do I do that? Do I have to change anything in template file? For all error message , i want it to appear before “row-wrap” class.

   

<div class="row">
    <ul class="woocommerce-error">
        <?php foreach ( $messages as $message ) : ?>
	  <li><?php echo wp_kses_post( $message ); ?></li>
       <?php endforeach; ?>
    </ul>


    <section class="row-wrap prod-wrap"> 
      <!-- WOOCOMMERCE ERROR appear here -->
	  <div class="row-inner">
	     <form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
      
       </form>
     </div>
    </section>
</div>

Related posts

3 comments

  1. You can move error message on woocommerce’s checkout page with jQuery:

    $('form.checkout.woocommerce-checkout').bind('DOMSubtreeModified',function(){
    if ($('ul.woocommerce-error').length) {
        $('ul.woocommerce-error').insertAfter('.place-order .blue-box')//where you want to place it
    }});
    
  2. I use this and work well:

    function move_woocommerce_message(){
      remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
      add_action( 'woocommerce_single_product_summary', 'wc_print_notices', 35 );  
    }
    add_filter('wp', 'move_woocommerce_message');
    
  3. The notices are printed by the wc_print_notices() function, which is added by WooCommerce to the following hooks:

    add_action( 'woocommerce_shortcode_before_product_cat_loop', 'wc_print_notices', 10 );
    add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
    add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
    

    To move them you must remove them from their existing locations and then add them to a new hook name.

    function so_34226268_remove_notices(){
        remove_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
        remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
        add_action( 'your_new_hook_location_here', 'wc_print_notices', 10 );
        add_action( 'another_new_hook_location', 'wc_print_notices', 10 );    
    }
    add_action( 'woocommerce_before_shop_loop', 'so_34226268_remove_notices', 1 );
    

Comments are closed.