Actions and Filters
There are a number of hooks provided in WooCommerce Private Store which let you customize the plugin’s behavior.
Please note that these code snippets are aimed at developers. If you feel comfortable using them, our article on how to use code snippets can serve as a helpful guide. If you don’t know how to use it then you should ask your developer. If you don’t have one then you can use our plugin customization service.
Filters
wc_private_store_lock_override
You can use this filter to override whether the store is currently locked (or unlocked). Return true
to indicate that the store is locked, and false
for unlocked:
add_action( 'wc_private_store_lock_override', 'wcps_lock_override' );
function wcps_lock_override( $is_locked ) {
if ( $xyz ) {
return false;
}
return $is_locked;
}
wc_private_store_before_login_form
This action fires before the store login form is output. You could use it to add additional markup around the form. E.g:
add_action( 'wc_private_store_before_login_form', 'wcps_before_login_form' );
function wcps_before_login_form() {
echo '<div class="container col-12">;
}
wc_private_store_after_login_form
This action fires after the store login form. E.g:
add_action( 'wc_private_store_after_login_form', 'wcps_after_login_form' );
function wcps_after_login_form() {
echo '</div>;
}
wc_private_store_login_form
This filter allows you to modify the HTML for the store login form before it’s displayed. E.g:
add_filter( 'wc_private_store_login_form', 'wcps_login_form' );
function wcps_login_form( $form_html ) {
// do something with form
return $form_html;
}
wc_private_store_password_expires
The store login is handled using a cooke which is set when the user enters the correct password. You can set the cookie expiry time (i.e. how long the user remains logged in) from the plugin settings page under WooCommerce → Settings → Products → Private Store. However, if you want more fine-grained control, you can use this filter.
The return value should be Unix timestamp in seconds since the epoch. The easiest way to set this is to use the time()
function and add the number of seconds you want to it. For example, to expire the cookie after 4 hours, add this code to your theme:
add_filter( 'wc_private_store_password_expires', 'wcps_password_expiry' );
function wcps_password_expiry( $expires ) {
return 4 * HOUR_IN_SECONDS;
}
wc_private_store_login_redirect
The filter allows you to override the URL the user is redirected to after successfully logging in to your store. You can set a global redirect from the plugin settings page, but if you want to do something more custom, use this filter.
add_filter( 'wc_private_store_login_redirect', 'wcps_login_redirect' );
function wcps_login_redirect( $url ) {
// set url as required
return $url;
}