在woocommerce的店面标题上,对于未登录的用户,我希望用两个金色引导按钮替换搜索框区域:"Login“、"Register”(如堆栈溢出登陆页标题),以将客人发送到我的自定义登录/注册urls。在您的帮助下,我有了这个PHP和CSS片段,它们可以很好地隐藏搜索框以供未登录的用户使用,但我不知道下一步该做什么:
add_filter( 'body_class', 'add_body_class_for_guest' );
function add_body_class_for_guest( $classes ) {
// Only for non logged users
if( ! is_user_logged_in() ) {
$classes[] = 'not-logged';
}
return $classes;
}CSS:
.not-logged .site-header .site-search { display: none; }发布于 2020-12-17 00:06:23
若要用链接到登录/注册页的按钮替换“店面搜索”框,对于未登录的用户,您可以使用以下选项(所以不要使用代码并删除CSS规则)
add_action( 'storefront_header', 'custom_storefront_header_search', 1 );
function custom_storefront_header_search() {
// Only for non logged users
if( ! is_user_logged_in() ) {
remove_action( 'storefront_header', 'storefront_product_search', 40 ); // remove search box
add_action( 'storefront_header', 'storefront_product_search_replacement', 40 ); // Replacement
}
}
// Function that displays the replacement buttons
function storefront_product_search_replacement() {
?>
<div class="site-search login-register">
<a href="<?php echo wc_get_page_permalink('myaccount'); ?>" class="button"><?php _e('Login / Register', 'woocommerce'); ?></a>
</div>
<?php
}代码位于活动子主题(或活动主题)的functions.php文件中。测试和工作。
现在您将能够添加自定义按钮html代码并按您喜欢的…对它们进行样式设置。
您将为来宾用户获得以下信息:

https://stackoverflow.com/questions/65331524
复制相似问题