php - woo-commerce password protected products display with out any restriction for some users -
php - woo-commerce password protected products display with out any restriction for some users -
i have created 'password protected' products back-end. want display 'password protected' products particular users, out password restriction. remaining users should inquire password view product. possible. please allow me know if solution.
in short terms, need alter wordpress visibility options functions.php
thanks, satya
after research on wordpress inbuilt functionality, got solution , working.
in 'functions.php' file did next code.
function password_visibility(){ $post = get_post(); if(!is_admin() && !empty($post->post_password)): require_once abspath . wpinc . '/class-phpass.php'; $hasher = new passwordhash( 8, true ); $expire = apply_filters( 'post_password_expires', time() + 10 * day_in_seconds ); $secure = ( 'https' === parse_url( home_url(), php_url_scheme ) ); setcookie( 'wp-postpass_' . cookiehash, $hasher->hashpassword( wp_unslash( $post->post_password ) ), $expire, cookiepath, cookie_domain, $secure ); wp_safe_redirect( wp_get_referer() ); endif; } add_action( 'pre_get_posts' , 'password_visibility' );
hope may help others have same requirement. can utilize code particular users or particular categories,etc..
php wordpress wordpress-plugin woocommerce password-protection
Comments
Post a Comment