Created
June 28, 2018 14:37
-
-
Save mattpramschufer/92896896c4f266554f956d7b122e6db5 to your computer and use it in GitHub Desktop.
DataTables Integration for WooCommerce Pay Per Post Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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