Last active
February 19, 2019 12:37
-
-
Save gabrielmerovingi/f13018616f03a0b318c8ce3a3ba2836d to your computer and use it in GitHub Desktop.
Example of how you can add a dedicated points history page in WooCommerce's My Account page.
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
/** | |
* Add Points Endpoint | |
* @version 1.0 | |
*/ | |
function mycred_pro_add_points_history_to_woo( $items ) { | |
$items['points'] = 'Points History'; | |
return $items; | |
} | |
add_filter( 'woocommerce_account_menu_items', 'mycred_pro_add_points_history_to_woo' ); | |
function mycred_pro_add_woo_history_endpoint() { | |
add_rewrite_endpoint( 'points', EP_ROOT | EP_PAGES ); | |
} | |
add_action( 'init', 'mycred_pro_add_woo_history_endpoint' ); | |
/** | |
* Points History Page | |
* @version 1.0 | |
*/ | |
function mycred_pro_woo_point_history_page( $page = 1 ) { | |
if ( strlen( $page ) == 0 ) $page = 1; | |
$args = array(); | |
$args['ctype'] = MYCRED_DEFAULT_TYPE_KEY; | |
$args['user_id'] = get_current_user_id(); | |
$args['paged'] = $page; | |
$args['number'] = 5; | |
$log = new myCRED_Query_Log( $args ); | |
?> | |
<div class="mycred-history-wrapper"> | |
<form class="form-inline" role="form" method="get" action=""> | |
<div class="row pagination-top"> | |
<div class="col-sm-6"> | |
<?php | |
if ( $page > 1 ) { | |
if ( $page > 2 ) | |
echo '<a href="' . wc_get_account_endpoint_url( 'points' ) . ( $page - 1 ) . '">Newer Entries</a>'; | |
else | |
echo '<a href="' . wc_get_account_endpoint_url( 'points' ) . '">Newer Entries</a>'; | |
} | |
echo '</div><div class="col-sm-6">'; | |
if ( $log->max_num_pages > $page ) | |
echo '<a href="' . wc_get_account_endpoint_url( 'points' ) . ( $page + 1 ) . '/">Older Entries</a>'; | |
?> | |
</div> | |
</div> | |
<?php $log->display(); ?> | |
</form> | |
</div> | |
<?php | |
} | |
add_action( 'woocommerce_account_points_endpoint', 'mycred_pro_woo_point_history_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment