更改WooCommerce通知在店面主题中的位置 [英] Change the position of of WooCommerce notices in storefront theme
本文介绍了更改WooCommerce通知在店面主题中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更改Storefront(WooCommerce)子主题中storefront_shop_messages的位置.所以我在活动主题的functions.php中添加了以下代码:
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 );
但这是行不通的.
推荐答案
在评论中获得期望的正确方法(意味着仅在产品单页上的添加到购物车"按钮后显示WooCommerce通知):
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 );
}
代码会出现在您活动的子主题(或主题)的function.php文件或任何插件文件中.
使用WooCommerce 3.1+测试并处理店面主题
Tested and works on storefront theme with WooCommerce 3.1+
这篇关于更改WooCommerce通知在店面主题中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文