WordPress – Woocommerce Pay Per Post with Woocommerce thumbnail modification for has access shortcode.

Plugin I use is the premium version of https://wordpress.org/plugins/woocommerce-pay-per-post/ , the basic free version may not work with this, I am not sure.

I have seen many people asking for thumbnails to show in the default list view, I am only using the ‘has access’ argument for the shortcode myself. I will include below the modified code for shortcode-has_access.php , this file should be saved into your current WP theme directory that way when PPP is updated this file won’t be overwritten.

// The shortcode for this specific page to render.

[woocommerce-payperpost template='has_access']

I made this edit just for sharing with included internal css to simply center a thumbnail with text link below so it’s all in one file. This can be improved with better styling using flex or grid css, but should get anyone started by just modifying the ‘my-content’ class in the upper html <style> custom code </style> part. You can also just remove all the upper HTML and copy the .my-content class code and add it to custom CSS in WordPress appearance options.

Modifications are, added thumbnail with link to post if clicked, removed <ul> unordered list, centered text and photo with text-align added to html boilerplate. Update note on the error message for no access near the bottom should also have the the my-content class added to the <p> like <p class=”my-content”> or a new class of my-content-error with special styling, updated the code to fix this.

Do not edit this file directly. You can copy this file to your theme directory * in /your-theme/woocommerce-pay-per-post/shortcode-has_access.php

        <!-- Below in between <style> tags is simple css class .my-content to center everything, you can make this way better.-->
<style type="text/css">
        .my-content {

 * Do not edit this file directly.  You can copy this file to your theme directory
 * in /your-theme/woocommerce-pay-per-post/shortcode-has_access.php
 * The $purchased variable is a WP Posts Object of purchased posts.
<div class="wc-ppp-purchased-container">
	<?php if ( count( $purchased ) > 0 ) : ?>
        <div class="my-content">
        <?php foreach ( $purchased as $post ) : ?>
          <?php $ppplink = esc_url( get_permalink( $post->ID ) ); ?>
          <!-- The array(400,400) is the size width, height of thumbnail-->
          <a href="<?php echo $ppplink; ?>"><?php echo get_the_post_thumbnail( $post->ID, array(400,400) ); ?></a></br> 
          <a href="<?php $ppplink; ?>"><?php echo esc_html( $post->post_title ); ?></a><br>
        <?php endforeach; ?>
	<?php else : ?>
        <p class="my-content"><?php /** @noinspection PhpVoidFunctionResultUsedInspection */
                apply_filters('wc_pay_per_post_shortcode_has_access_no_posts', _e('You do not have access to any content right now.', 'wc_pay_per_post' ) ); ?></p>
	<?php endif; ?>
For more info on sizes of thumbnail, I used array(400,400) because It was easier to remember.

Leave a Comment