Skip to content

Commit

Permalink
feat(subscriptions): sortable columns
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Mar 8, 2024
1 parent 67569b5 commit 4947894
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions includes/hub/admin/class-subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
* Class to handle the Subscriptions admin page by customizing the Custom Post type screen
*/
class Subscriptions extends Woo {
/**
* Runs the initialization.
*/
public static function init() {
parent::init();
add_filter( 'manage_edit-' . \Newspack_Network\Hub\Database\Subscriptions::POST_TYPE_SLUG . '_sortable_columns', [ __CLASS__, 'subscription_sortable_columns' ] );
}

/**
* Modify columns on post type table
Expand Down Expand Up @@ -47,7 +54,6 @@ public static function posts_columns( $columns ) {
* @return void
*/
public static function posts_columns_values( $column, $post_id ) {

$store_class_name = str_replace( 'Admin', 'Stores', get_called_class() );
$item = $store_class_name::get_item( $post_id );

Expand Down Expand Up @@ -103,7 +109,7 @@ public static function posts_columns_values( $column, $post_id ) {
case 'orders':
$link = sprintf(
'%s/wp-admin/edit.php?post_status=all&post_type=shop_order&_subscription_related_orders=%d',
$item->get_node_url(),
$item->get_node_url(),
$item->get_remote_id()
);
printf( '<a href="%s" target="blank">%s</a>', $link, $item->get_payment_count() ); // phpcs:ignore
Expand All @@ -113,4 +119,22 @@ public static function posts_columns_values( $column, $post_id ) {
break;
}
}

/**
* Add sortable columns.
*
* @param array $columns Columns.
* @return array
*/
public static function subscription_sortable_columns( $columns ) {
$sortable_columns = [
'start_date' => 'start_date',
'trial_end_date' => 'trial_end_date',
'next_payment_date' => 'next_payment_date',
'last_payment_date' => 'last_payment_date',
'end_date' => 'end_date',
];

return wp_parse_args( $sortable_columns, $columns );
}
}

0 comments on commit 4947894

Please sign in to comment.