繁体   English   中英

隐藏登录用户的简短描述文本

[英]Hiding short description text for Logged In users

我有以下代码,在 woocommerce 中向我的网站上的新访问者显示我的产品简短描述上方的文本。 根据文本执行所需的操作(创建帐户)后,我想隐藏不再需要的文本。

add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
    echo 'To check if this item qualifies for a discount <a href="https://www.livestainable.co.za/my-account-2/"><u><strong>Log In or Create</strong></u></a> an account.</br></br>';
    return $description.$text;
}

要仅为客人显示一些文字,只需使用! is_user_logged_in() ! is_user_logged_in()IF语句中,就像在这个重新访问的代码中一样:

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="https://www.livestainable.co.za/my-account-2/"><u><strong>' . __("Log In or Create") . '</strong></u></a>' ) . '</p>' . $description;
    }
    return $description;
}

代码进入活动子主题(或活动主题)的functions.php文件。 测试和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM