get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array( $columns, $hidden, $sortable ); $query = $this->table_data(); if ( is_wp_error( $query ) ) { $this->items = []; return; } $this->set_pagination_args( [ 'total_items' => $query->pagination->count, 'per_page' => $this->get_items_per_page( 'orders' ), ] ); $this->items = $query->data; } public function search() { ?>
search_box( __( 'Search Subscriptions', 'surecart' ), 'order' ); ?>
__( 'All', 'surecart' ), 'active' => __( 'Active', 'surecart' ), 'trialing' => __( 'Trialing', 'surecart' ), 'past_due' => __( 'Past Due', 'surecart' ), 'canceled' => __( 'Canceled', 'surecart' ), ]; foreach ( $stati as $status => $label ) { $link = \SureCart::getUrl()->index( 'subscriptions' ); $current_link_attributes = ''; if ( ! empty( $_GET['status'] ) ) { if ( $status === $_GET['status'] ) { $current_link_attributes = ' class="current" aria-current="page"'; } } elseif ( 'all' === $status ) { $current_link_attributes = ' class="current" aria-current="page"'; } $link = add_query_arg( 'status', $status, $link ); $link = esc_url( $link ); $status_links[ $status ] = "" . $label . ''; } /** * Filters the comment status links. * * @since 2.5.0 * @since 5.1.0 The 'Mine' link was added. * * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine', * 'Pending', 'Approved', 'Spam', and 'Trash'. */ return apply_filters( 'surecart/subscription/index/links', $status_links ); } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return Array */ public function get_columns() { return array_merge( [ 'customer' => __( 'Customer', 'surecart' ), 'status' => __( 'Status', 'surecart' ), 'plan' => __( 'Plan', 'surecart' ), 'remaining_payments' => __( 'Remaining Payments', 'surecart' ), 'integrations' => __( 'Integrations', 'surecart' ), 'created' => __( 'Created', 'surecart' ), 'mode' => '', ], parent::get_columns() ); } /** * Displays the checkbox column. * * @param Product $product The product model. */ public function column_cb( $product ) { ?> purchase->product ?? null; $output = $product ? $this->productIntegrationsList( [ 'product_id' => $product, 'price_id' => $subscription->purchase->price->id ?? $subscription->purchase->price ?? null, 'variant_id' => $subscription->purchase->variant->id ?? $subscription->purchase->variant ?? null, ] ) : false; return $output ? $output : '-'; } /** * Define which columns are hidden * * @return Array */ public function get_hidden_columns() { return array(); } /** * Define the sortable columns * * @return Array */ public function get_sortable_columns() { return array( 'title' => array( 'title', false ) ); } /** * Get the table data * * @return Array */ protected function table_data() { $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); $conditions = [ 'status' => $this->getStatus(), 'query' => $this->get_search_query(), ]; if ( ! empty( $mode ) ) { $conditions['live_mode'] = 'live' === $mode; } return Subscription::where( $conditions ) ->with( [ 'customer', 'price', 'price.product', 'current_period', 'purchase' ] ) ->paginate( [ 'per_page' => $this->get_items_per_page( 'subscriptions' ), 'page' => $this->get_pagenum(), ] ); } /** * Get the archive query status. * * @return boolean|null */ public function getStatus() { $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? null ) ); if ( 'all' === $status ) { $status = null; } return $status ? [ esc_html( $status ) ] : []; } /** * The remaining payments for the subscription * * @param \SureCart\Models\Subscription $subscription The subscription model. * * @return string */ public function column_remaining_payments( $subscription ) { // handle non-finite subscriptions. if ( ! $subscription->finite ) { return 'completed' === $subscription->status ? '-' : '∞'; } // handle payment plans. return 0 === $subscription->remaining_period_count ? __( 'None', 'surecart' ) : (int) $subscription->remaining_period_count; } /** * The subscription type * * @param \SureCart\Models\Subscription $subscription The subscription model. * * @return string */ // public function column_type( $subscription ) { // if ( null === $subscription->remaining_period_count ) { // return '' . __( 'Subscription', 'surecart' ) . ''; // } // return '' . __( 'Payment Plan', 'surecart' ) . ''; // } /** * Handle the total column * * @param \SureCart\Models\Subscription $subscription Checkout Session Model. * * @return string */ public function column_plan( $subscription ) { ob_start(); echo ! empty( $subscription->ad_hoc_display_amount ) ? esc_html( $subscription->ad_hoc_display_amount ) : esc_html( $subscription->price->display_amount ); echo ' ' . esc_html( $subscription->price->interval_text ); echo ' ' . esc_html( $subscription->price->interval_count_text ); echo wp_kses_post( $this->getProductDisplay( $subscription ) ); if ( ! empty( $subscription->variant_options ) ) { echo '
' . esc_html( implode( ' / ', $subscription->variant_options ) ) . '
'; } return ob_get_clean(); } private function getProductDisplay( $subscription ) { if ( empty( $subscription->price->product->name ) ) { return esc_html( $subscription->price->name ?? __( 'No Product', 'surecart' ) ); } $price_name = ! empty( $subscription->price->name ) ? ' - ' . esc_html( $subscription->price->name ) : ''; return '
' . esc_html( $subscription->price->product->name ) . '' . $price_name; } public function getInterval( $interval, $count, $separator = '/', $show_single = false ) { switch ( $interval ) { case 'day': return " $separator " . sprintf( // translators: %d is the number of days. $show_single ? _n( '%d day', '%d days', $count, 'surecart' ) : _n( '%d day', '%d days', $count, 'surecart' ), $count ); case 'week': return " $separator " . sprintf( // translators: %d is the number of weeks. $show_single ? _n( '%d week', '%d weeks', $count, 'surecart' ) : _n( '%d week', '%d weeks', $count, 'surecart' ), $count ); case 'month': return " $separator " . sprintf( // translators: %d is the number of months. $show_single ? _n( '%d month', '%d months', $count, 'surecart' ) : _n( '%d month', '%d months', $count, 'surecart' ), $count ); case 'year': return " $separator " . sprintf( // translators: %d is the number of years. $show_single ? _n( '%d year', '%d years', $count, 'surecart' ) : _n( '%d year', '%d years', $count, 'surecart' ), $count ); } } /** * Output the Promo Code * * @param Promotion $promotion Promotion model. * * @return string */ public function column_usage( $promotion ) { $max = $promotion->max_redemptions ?? '∞'; ob_start(); ?> times_redeemed / $max" ); ?>
get_expiration_string( $promotion->redeem_by ) ); ?>
duration ) ) { return; } if ( ! empty( $coupon->percent_off ) ) { $percent = sprintf( '%d%%', (int) $coupon->percent_off ); // translators: %s is the discount percentage (e.g. "10%"). return esc_html( sprintf( __( '%s off', 'surecart' ), $percent ) ); } if ( ! empty( $coupon->amount_off ) ) { // translators: Coupon amount off. return Currency::formatCurrencyNumber( $coupon->amount_off ) . ' ' . strtoupper( esc_html( $coupon->currency ) ) . ''; } return esc_html__( 'No discount.', 'surecart' ); } /** * Get the duration string * * @param Coupon|boolean $coupon Coupon object. * @return string|void; */ public function get_duration_string( $coupon = '' ) { if ( ! $coupon || empty( $coupon->duration ) ) { return; } if ( 'forever' === $coupon->duration ) { return __( 'Forever', 'surecart' ); } if ( 'repeating' === $coupon->duration ) { // translators: number of months. return sprintf( __( 'For %d months', 'surecart' ), $coupon->duration_in_months ?? 1 ); } return __( 'Once', 'surecart' ); } /** * Handle the status * * @param \SureCart\Models\Subscription $subscription Subscription model. * * @return string */ public function column_status( $subscription ) { \SureCart::assets()->addComponentData( 'sc-subscription-status-badge', '#subscription-' . esc_attr( $subscription->id ), [ 'subscription' => $subscription, ] ); return ''; } /** * Name of the coupon * * @param \SureCart\Models\Promotion $promotion Promotion model. * * @return string */ public function column_customer( $subscription ) { ob_start(); $name = $subscription->customer->name ?? ''; if ( ! $name ) { $name = $subscription->customer->email ?? __( 'No name provided', 'surecart' ); } ?> row_actions( [ 'edit' => '' . __( 'Edit', 'surecart' ) . '', ], ); ?>
mode_dropdown(); /** * Fires before the Filter button on the Posts and Pages list tables. * * The Filter button allows sorting by date and/or category on the * Posts list table, and sorting by date on the Pages list table. * * @since 2.1.0 * @since 4.4.0 The `$post_type` parameter was added. * @since 4.6.0 The `$which` parameter was added. * * @param string $post_type The post type slug. * @param string $which The location of the extra table nav markup: * 'top' or 'bottom' for WP_Posts_List_Table, * 'bar' for WP_Media_List_Table. */ do_action( 'restrict_manage_subscriptions', $this->screen->post_type, $which ); $output = ob_get_clean(); if ( ! empty( $output ) ) { echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) ); } } ?>