Search code examples
phpwordpresswoocommercenoticestorefront

Change the position of of WooCommerce notices in storefront theme


I am trying to change the position of storefront_shop_messages in my Storefront (WooCommerce) child theme. So I have added this code in the functions.php of my active theme:

remove_action( 'storefront_content_top', 'storefront_shop_messages', 15 );
add_action('woocommerce_product_meta_end', 'storefront_shop_messages', 1 );

But it doesn't work.


Solution

  • The correct way to get what you are expecting in your comments (meaning displaying WooCommerce notices after add to cart button on product single page only):

    add_action( 'wp_head', 'customize_notices' );
    function customize_notices(){
        if( is_product() )
            remove_action( 'storefront_content_top', 'storefront_shop_messages', 15 );
        remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
        add_action( 'woocommerce_single_product_summary', 'woocommerce_before_main_content', 34 );
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and works on storefront theme with WooCommerce 3.1+