Skip to content

Instantly share code, notes, and snippets.

@mattpramschufer
Created June 28, 2018 14:37
Show Gist options
  • Save mattpramschufer/92896896c4f266554f956d7b122e6db5 to your computer and use it in GitHub Desktop.
Save mattpramschufer/92896896c4f266554f956d7b122e6db5 to your computer and use it in GitHub Desktop.
DataTables Integration for WooCommerce Pay Per Post Plugin
<?php
/**
* Do not edit this file directly. You can copy this file to your theme directory
* in /your-theme/woocommerce-pay-per-post/shortcode-purchased.php
* The $purchased variable is a WP Posts Object of purchased posts.
*/
?>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<div class="wc-ppp-purchased-container">
<?php if ( count( $purchased ) > 0 ): ?>
<table id="data-table">
<thead>
<tr>
<th>Title</th>
<th>Category</th>
<th>Tags</th>
<th>Post Date</th>
</tr>
</thead>
<tbody>
<?php foreach ( $purchased as $post ): ?>
<tr>
<td><a href="<?php echo get_permalink( $post->ID ); ?>"><?php echo $post->post_title; ?></a></td>
<td>
<?php
$categories = get_the_category( $post->ID );
$category_array = array();
if ( $categories ) {
foreach ( $categories as $category ) {
$category_array[] = $category->name;
}
}
echo implode( ', ', $category_array );
?>
</td>
<td>
<?php
$tags = get_the_tags( $post->ID );
$tags_array = array();
if ( $tags ) {
foreach ( $tags as $tag ) {
$tags_array[] = $tag->name;
}
}
echo implode( ', ', $tags_array );
?>
</td>
<td><?php echo date( 'm/d/Y', strtotime( $post->post_date ) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p>You have not purchased any protected posts.</p>
<?php endif; ?>
</div>
<script>
(function ($) {
'use strict';
$(function () {
$('#data-table').DataTable();
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment