• Resolved karlwithak23

    (@karlwithak23)


    Hi Matt! Thanks for the plugin! I have a question – I see that the plugin can protect the content of that page, but what about content that is in Custom Fields, those created manually or via a plugin like Advanced Custom Fields? Thanks so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think you can achieve this by modifying the template. First, you need to determine if the person viewing the post has purchased the associated product, or if the post is not protected. Here is a somewhat messy example…

    $is_purchased = false;
    $str_products_payperpost = get_post_meta( get_the_ID(), 'woocommerce_ppp_product_id', true );
    $current_user = wp_get_current_user();
    $arr_ids_products = explode( ",", $str_products_payperpost );
    foreach ( $arr_ids_products as $id ) {
      $purchased = wc_customer_bought_product( $current_user->user_email, $current_user->ID, $id );
      // if purchased or if not proteted, show the page
      if ( $purchased || $id == '' ) {
        $is_purchased = true;
      }
    }

    Then you would wrap the custom fields in a conditional statement so they only show when appropriate. Something like this..

    <?php if( $is_purchased ){ ?>
      <div class="protected-custom-field">
        <!-- Your field here -->
      </div>
    <?php } ?>

    Thanks for the reply. I also found this plugin which I’ve just managed to get working… https://ww.wp.xz.cn/plugins/woocommerce-pay-per-post/

    Another thing you can do is render the fields into the editor. ACF has shortcode I believe for that.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Protect Content in Custom Fields?’ is closed to new replies.