如何对未登录的用户隐藏WooCommerce产品名称和简短说明?

时间:2022-02-03 作者:Amare

我使用这段代码来隐藏对已注销用户的简短描述,但它不起作用-它显示要求用户登录的消息,但仍然显示简短描述。

add_filter( \'woocommerce_short_description\', \'add_text_before_short_description_for_guests\' );
function add_text_before_short_description_for_guests( $description ) {
    // Only for guest users
    if ( ! is_user_logged_in() ) {
        $description = \'<p>\' . sprintf( __( "To check if this item qualifies for a discount %s an account."), \'<a href="my-account link goes here"><u><strong>\' . __("Log In or Create") . \'</strong></u></a>\' ) . \'</p>\' . $description;
    }
    return $description;
}
谢谢你

1 个回复
SO网友:Sébastien Serre

你的$description 显示,因为您在中连接了它是您的条件

$description = \'

\' . sprintf( __( "To check if this item qualifies for a discount %s an account."), \'\' . __("Log In or Create") . \'\' ) . \'
\' . $description; 
下面的代码有帮助吗?

add_filter( \'woocommerce_short_description\', \'add_text_before_short_description_for_guests\' );
function add_text_before_short_description_for_guests( $description ) {
    // Only for guest users
    if ( ! is_user_logged_in() ) {
        $description = sprintf( __( "To check if this item qualifies for a discount %s an account.", \'your_textdomain\' ), \'\' . __( "Log In or Create", \'your_textdomain\' )  );
    }

    return $description;
}
不要忘记添加你自己的或你的主题(我不知道)文本域来轻松翻译你的作品。

相关推荐

如何在Functions.php中链接style.css

我是WordPress的新手;我刚开始学习WordPress。我想把风格联系起来。函数中的css。php,但我无法解决这里可能存在的问题。谁能给我指出正确的方向吗?指数php<?php get_header(); ?> <?php if ( have_posts() ) { while ( have_posts() ) { the_post();