Skip to main content

Grant access based on WooCommerce product purchase

Free Intermediate Since v1.0.0

Benecaster’s bridge system handles subscription-based access, but sometimes access should be granted based on a one-time product purchase rather than a recurring membership. This recipe uses benecaster_episode_is_accessible to check WooCommerce order history and grant access to specific episodes when the customer has purchased a linked product.

Code

<?php
// Grant free-preview tagged episodes to all logged-in users.
add_filter( 'benecaster_episode_is_accessible', function( bool $access, int $episode_id, int $user_id, string $tier_slug ): bool {
    if ( $user_id > 0 && has_term( 'free-preview', 'category', $episode_id ) ) {
        return true;
    }
    return $access;
}, 10, 4 );

View on GitHub →

Hooks Used