繁体   English   中英

使用Yith WooCommerce愿望清单插件登录之前如何隐藏所有产品上的愿望清单按钮?

[英]How can hide wishlist button on all product before login using Yith WooCommerce wishlist plugin?

我想在登录前在所有产品上隐藏心愿单按钮。 我想在所有产品和单个产品页面上登录之前禁用心愿单按钮。 我已经在function.php中尝试过,但是失败了。

function login_wishlist(){
    if(is_user_logged_in()) { return true;}else{ return false;}
}
add_action('yith_wcwl_add_to_wishlist', 'login_wishlist');

我不知道该怎么办,请问有什么可以帮助的吗?

试试这个,让我知道输出。

add_filter('yith_wcwl_positions', 'only_show_to_logged_in_user');

function only_show_to_logged_in_user($so_array=array()){
    if(!is_user_logged_in()){
        $so_array   =   array(
            "shortcode" => array("hook"=>'', 'priority'=>0)
        );
    }
    return $so_array;
}

注意:未经测试。

EDITED

其他快速解决方案是,如果用户未使用jQuery登录,则将其隐藏。

add_action('wp_footer', 'only_show_to_logged_in_user_1');

function only_show_to_logged_in_user_1(){
    if(!is_user_logged_in()){

        echo "<script>";
            echo "jQuery('.add_to_wishlist').hide();";
        echo "</script>";

    }
}

暂无
暂无

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

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