如何使用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;
}

注意:未测试。

已编辑

另一个快速解决方案是,若用户并没有使用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>";
    }
}