Short answer: You cannot use WordPress logic in your HTML file because WP is not loaded when you call your HTML.
There are many ways you could protect your content. It’s hard to give you a fitting suggestion without knowing your whole buying context.
Nonetheless, here’s a couple of suggestions I can think of.
- Create a protected WordPress page on your site that only people with the password would have access. You can put your HTML content on that page and send the password to those who have bought your digital product.
- Create a specific role on your site with limited capabilities, like
access_digital_product
and use WP conditionalif( current_user_can( 'access_digital_product' ) ) { // Then show page content }
. People that buy need to register an account on your site. - Have the content of your HTML page outputted by a PHP function, and call that function only when people have bought your digital product. Hooking to
template_redirect
. Something likeadd_action( 'template_redirect', 'digital_product_buy_check' );
|function digital_product_buy_check(){ if( $_GET[ 'buying_success' ] ) { // Show content }
- And probably many more ways I’m not thinking of right now
The main point is that you cannot effectively protect your content in the HTML file with WP API because WP is not active in your HTML. But I guess it all depends what kind of protection you are looking for. You could just send the link to those who have bought your digital_product
keeping it secret (using noindex and maybe htaccess
passwords). But then anyone who has the link would have access to that page. Up to you to decide 🙂