$posts_array = get_posts($args); switch ($atts['template']) { case "purchased": if (is_user_logged_in()) { foreach ($posts_array as $index => $post) { $productID = self::get(self::METAKEY, $post->ID); // var_dump($productID); if (!self::checkForProduct($productID)) { //Remove page if they have not purchased unset($posts_array[$index]); } } $posts_array = array_values($posts_array); $return = self::renderTemplate('purchased', $posts_array); } break; case "all": $return = self::renderTemplate('all', $posts_array); break; } return $return; } public static function renderTemplate($template = 'purchased', $data) { ob_start(); require WC_PPP_PATH . '/tpl/' . $template . '.php'; return ob_get_clean(); } } Woocommerce_PayPerPost::init(); }
<?php wp_nonce_field('woocommerce_ppp_nonce', 'woocommerce_ppp_nonce'); ?> <p> This is the id of the product that is required to have been purchased before a user can view the content of this page. You can enter in multiple IDs just seperate them with a comma.<br> <label for="woocommerce_ppp_product_id">Product ID: </label> <input type="text" name="woocommerce_ppp_product_id" id="woocommerce_ppp_product_id" value="<?php echo Woocommerce_PayPerPost::get(Woocommerce_PayPerPost::METAKEY); ?> " size="50" /> </p>