1. Home
  2. Knowledge Base
  3. WooCommerce Password Protected Categories
  4. Advanced Usage
  5. Developer documentation

Developer documentation

WooCommerce Password Protected Categories contains a number of hooks which you can use to customize the plugin’s behaviour.

Please note that this code is aimed at developers and if you don’t know how to use it then you should ask your developer. If you don’t have one, we recommend posting a job on Codeable. Alternatively, please contact us to request a quote from our customizations service.

wc_ppc_before_password_form

Action to take before the category password form. E.g:

add_action( 'wc_ppc_before_password_form', 'wc_ppc_before_password_form' );
function wc_ppc_before_password_form() {
    echo '<div class="container col-12">;
}

wc_ppc_after_password_form

Action to take after the category password form. E.g:

add_action( 'wc_ppc_after_password_form', 'wc_ppc_after_password_form' );
function wc_ppc_after_password_form() {
    echo '</div>;
}

wc_ppc_password_form

Filter which allows you to modify the HTML for the password form before it’s displayed. E.g:

add_filter( 'wc_ppc_password_form', 'wc_ppc_password_form' );
function wc_ppc_password_form( $form ) {
    // do something with form
    return $form;
}

post_password_expires

Filter which allows you to modify the expiration time for the password cookie; i.e. how long the user will be able to access the protected category before they need to re-enter their password. You can set this via the plugin options (WooCommerce > Settings > Products > Password Protected Categories), but if you want more fine-grained control over the expiry time, 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 8 hours:

add_filter( 'wc_ppc_password_expires', 'wc_ppc_password_expiry' );
function wc_ppc_password_expiry( $expires ) {
    return time() + 8 * HOUR_IN_SECONDS;
}

Was this article helpful?

Related Articles