$meta ) {
if ( isset( $meta->key ) && '_renew_subscrpt' !== $meta->key ) {
$temp_metas[ $key ] = $meta;
}
}
return $temp_metas;
}
/**
* Enqueue admin assets.
*
* @return void
*/
public function enqueue_scripts() {
wp_enqueue_style( 'subscrpt_admin_css' );
wp_enqueue_style( 'subscrpt_status_css' );
}
/**
* Remove default post actions.
*
* @param array $actions Actions.
*
* @return array
*/
public function post_row_actions( $actions ) {
global $current_screen;
if ( 'subscrpt_order' !== $current_screen->post_type ) {
return $actions;
}
unset( $actions['inline hide-if-no-js'] );
unset( $actions['view'] );
unset( $actions['trash'] );
unset( $actions['edit'] );
return $actions;
}
/**
* Register custom columns.
*
* @param array $columns Columns.
*
* @return array
*/
public function add_custom_columns( $columns ) {
$columns['subscrpt_start_date'] = __( 'Start Date', 'subscription' );
$columns['subscrpt_customer'] = __( 'Customer', 'subscription' );
$columns['subscrpt_next_date'] = __( 'Next Date', 'subscription' );
$columns['subscrpt_status'] = __( 'Status', 'subscription' );
unset( $columns['date'] );
unset( $columns['cb'] );
return $columns;
}
/**
* Display column data.
*
* @param string $column Column.
* @param int $post_id Post Id.
*
* @return void
*/
public function add_custom_columns_data( $column, $post_id ) {
// HPOS: Safe. Only retrieves WooCommerce order via CRUD, and subscription meta via post meta.
$order_id = get_post_meta( $post_id, '_subscrpt_order_id', true ); // HPOS: Only subscription meta, not order meta.
$order = wc_get_order( $order_id ); // HPOS: Safe, uses WooCommerce CRUD.
if ( $order ) {
if ( 'subscrpt_start_date' === $column ) {
$start_date = get_post_meta( $post_id, '_subscrpt_start_date', true );
echo ! empty( $start_date ) ? esc_html( wp_date( 'F d, Y', $start_date ) ) : '-';
} elseif ( 'subscrpt_customer' === $column ) {
?>
get_formatted_billing_full_name() ); ?>
get_billing_email() ); ?>
get_billing_phone() ) ) : ?>
Phone : get_billing_phone() ); ?>
label ); ?>
|null
*/
public static function get_info_rows( $subscription_id ) {
$order_id = get_post_meta( $subscription_id, '_subscrpt_order_id', true );
$order_item_id = get_post_meta( $subscription_id, '_subscrpt_order_item_id', true );
$trial = get_post_meta( $subscription_id, '_subscrpt_trial', true );
$start_date = get_post_meta( $subscription_id, '_subscrpt_start_date', true );
$next_date = get_post_meta( $subscription_id, '_subscrpt_next_date', true );
$trial_start_date = get_post_meta( $subscription_id, '_subscrpt_trial_started', true );
$trial_end_date = get_post_meta( $subscription_id, '_subscrpt_trial_ended', true );
$trial_mode = get_post_meta( $subscription_id, '_subscrpt_trial_mode', true );
$order = wc_get_order( $order_id );
if ( ! $order ) {
return null;
}
$order_item = $order->get_item( $order_item_id );
$product_name = $order_item->get_name();
$product_link = get_the_permalink( $order_item->get_product_id() );
// Get payment information
$product_id = $order_item->get_product_id();
$max_payments = subscrpt_get_max_payments( $subscription_id ) ? subscrpt_get_max_payments( $subscription_id ) : 0;
$payments_made = subscrpt_count_payments_made( $subscription_id );
$rows = array(
'product' => array(
'label' => __( 'Product', 'subscription' ),
'value' => '' . esc_html( $product_name ) . '',
),
'cost' => array(
'label' => __( 'Cost', 'subscription' ),
'value' => Helper::get_subscription_recurring_price_html( $subscription_id, $order_item ),
),
'quantity' => array(
'label' => __( 'Qty', 'subscription' ),
'value' => "x{$order_item->get_quantity()}",
),
);
// Add payment information if max_payments is set and not unlimited
if ( ! empty( $max_payments ) && $max_payments > 0 ) {
$rows['total_payments'] = array(
'label' => __( 'Total Payments', 'subscription' ),
'value' => esc_html( $payments_made ) . ' / ' . esc_html( $max_payments ),
);
}
$rows += array(
'start_date' => array(
'label' => __( 'Started date', 'subscription' ),
'value' => ! empty( $start_date ) ? wp_date( 'F d, Y', $trial && $trial_start_date ? $trial_start_date : $start_date ) : '-',
),
'next_date' => array(
'label' => __( 'Payment due date', 'subscription' ),
'value' => ! empty( $next_date ) ? wp_date( 'F d, Y', $trial && $trial_end_date && 'on' === $trial_mode ? $trial_end_date : ( $next_date ?? '-' ) ) : '-',
),
'status' => array(
'label' => __( 'Status', 'subscription' ),
'value' => '' . get_post_status_object( get_post_status( $subscription_id ) )->label . '',
),
'payment_method' => array(
'label' => __( 'Payment Method', 'subscription' ),
'value' => empty( $order->get_payment_method_title() ) ? '-' : $order->get_payment_method_title(),
),
'billing_address' => array(
'label' => __( 'Billing', 'subscription' ),
'value' => $order->get_formatted_billing_address() ? $order->get_formatted_billing_address() : __( 'No billing address set.', 'subscription' ),
),
'shipping_address' => array(
'label' => __( 'Shipping', 'subscription' ),
'value' => $order->get_formatted_shipping_address() ? $order->get_formatted_shipping_address() : __( 'No shipping address set.', 'subscription' ),
),
);
if ( $trial ) {
$rows = array_slice( $rows, 0, 3, true ) + array(
'trial' => array(
'label' => __( 'Trial', 'subscription' ),
'value' => $trial,
),
'trial_period' => array(
'label' => __( 'Trial Period', 'subscription' ),
'value' => ( $trial_start_date && $trial_end_date ? ' [ ' . wp_date( 'F d, Y', $trial_start_date ) . ' - ' . wp_date( 'F d, Y', $trial_end_date ) . ' ] ' : __( 'Trial isn\'t activated yet! ', 'subscription' ) ),
),
) + array_slice( $rows, 3, count( $rows ) - 1, true );
}
if ( class_exists( 'WC_Stripe' ) && 'stripe' === $order->get_payment_method() ) {
$is_auto_renew = get_post_meta( $subscription_id, '_subscrpt_auto_renew', true );
$new_rows = array();
foreach ( $rows as $key => $value ) {
$new_rows[ $key ] = $value;
if ( 'payment_method' === $key ) {
$new_rows['stripe_auto_renewal'] = array(
'label' => __( 'Stripe Auto Renewal', 'subscription' ),
'value' => '0' !== $is_auto_renew ? 'On' : 'Off',
);
}
}
$rows = $new_rows;
}
$rows = apply_filters( 'subscrpt_admin_info_rows', $rows, $subscription_id, $order );
return $rows;
}
/**
* Apply a status change to a subscription.
*
* Updates the subscription post status, fires the admin status-change email
* notification, runs the subscription status action, and completes the
* related order when the subscription becomes active. Called from the
* standalone subscription details page.
*
* @param int $post_id Subscription (subscrpt_order) post ID.
* @param string $action Target status slug.
*
* @return void
*/
public static function process_status_change( $post_id, $action ) {
$old_status = get_post_status( $post_id );
wp_update_post(
array(
'ID' => $post_id,
'post_status' => $action,
)
);
if ( $old_status !== $action ) {
$old_status_object = get_post_status_object( $old_status );
$new_status_object = get_post_status_object( $action );
WC()->mailer();
do_action( 'subscrpt_status_changed_admin_email_notification', $post_id, $old_status_object->label, $new_status_object->label );
}
$order_id = get_post_meta( $post_id, '_subscrpt_order_id', true );
if ( 'active' === $action ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$order->update_status( 'completed' );
}
Action::status( $action, $post_id );
} else {
Action::status( $action, $post_id );
}
}
public function add_subscription_filter_select() {
// Implementation of add_subscription_filter_select method
}
public function add_overview_submenu() {
// Remove and re-add submenu to ensure Overview is first
remove_submenu_page( 'edit.php?post_type=subscrpt_order', 'edit.php?post_type=subscrpt_order' );
add_submenu_page(
'edit.php?post_type=subscrpt_order',
__( 'Overview', 'subscription' ),
__( 'Overview', 'subscription' ),
'manage_options',
'subscription_overview',
array( $this, 'render_overview_page' ),
0
);
add_submenu_page(
'edit.php?post_type=subscrpt_order',
__( 'All Subscriptions', 'subscription' ),
__( 'All Subscriptions', 'subscription' ),
'manage_options',
'edit.php?post_type=subscrpt_order',
'',
1
);
if ( ! class_exists( 'Sdevs_Wc_Subscription_Pro' ) ) {
add_submenu_page(
'edit.php?post_type=subscrpt_order',
__( 'Go Pro', 'subscription' ),
__( 'Go Pro', 'subscription' ),
'manage_options',
'wp_subscription_go_pro',
array( $this, 'render_go_pro_page' ),
99
);
}
}
public function render_overview_page() {
?>