php - woo-commerce password protected products display with out any restriction for some users -
I created some 'password protected' products from back-end. Now I have created those 'password protected' products to a particular user , I want to display with any password restriction. For the remaining users, they should ask for the password to see the product. Is it possible. Please tell me if there is a solution.
In short, need to change the WordPress visibility option from the workspace
thanks, true
After doing some research on WordPress built-in functionality, I have got a solution and it has to work.
In the 'functions.php' file I did the following code.
function password_view () {$ post = get_post (); If (! Is_admin () & amp; Empty ($ post- & gt; Post_password)): require_once abspath WPIN '/class-phpass.php'; $ Hashar = new passwordHash (8, true); $ Expire = apply_filters ('post_password_expires', time () + 10 * DAY_IN_SECONDS); $ Secure = ('https' === parse_url (home_url (), PHP_URL_SCHEME); Setkey ('wp-postpass_'. COOKIEHASH, $ hashcher- & gt; hash password (wp_unslash ($ post- & gt; post_password)), $ ending, cookiepate, cookie_deman, $ secure); Wp_safe_redirect (wp_get_referer ()); end if; } Add_action ('pre_get_posts', 'password_visibility');
Hope it can help some other people who have the same requirements. I can use this code for certain users or special categories.
Comments
Post a Comment