Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active February 28, 2019 06:27
Show Gist options
  • Save bekarice/a311844430e217be67b4 to your computer and use it in GitHub Desktop.
Save bekarice/a311844430e217be67b4 to your computer and use it in GitHub Desktop.
Add custom EDD payment statuses
<?php // only copy if needed
/**
* Adds new payment statuses to array of available statuses
*
* @param string[] $payment_statuses the core payment statuses
* @param string[] updated set of statuses
*/
function sww_add_edd_payment_statuses( $payment_statuses ) {
$payment_statuses['invoice_paid'] = 'Invoice Paid';
$payment_statuses['in_progress'] = 'Project in progress';
return $payment_statuses;
}
add_filter( 'edd_payment_statuses', 'sww_add_edd_payment_statuses' );
/**
* Adds our new statuses as post statuses so we can use them in Payment History navigation
*/
function sww_register_post_type_statuses() {
// Payment Statuses
register_post_status( 'invoice_paid', array(
'label' => _x( 'Invoice Paid', 'Invoice paid payment status', 'sww-edd' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Invoice Paid <span class="count">(%s)</span>', 'Invoice Paid <span class="count">(%s)</span>', 'sww-edd' )
) );
register_post_status( 'in_progress', array(
'label' => _x( 'Project in progress', 'In progress payment status', 'sww-edd' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'In progress <span class="count">(%s)</span>', 'In progress <span class="count">(%s)</span>', 'sww-edd' )
) );
}
add_action( 'init', 'sww_register_post_type_statuses' );
/**
* Adds our new payment statuses to the Payment History navigation
*
* @param string[] $views payment table views
* @param string[] updated views
*/
function sww_edd_payments_new_views( $views ) {
$views['invoice_paid'] = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'status' => 'invoice_paid', 'paged' => FALSE ) ), 'Invoice paid' );
$views['in_progress'] = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'status' => 'in_progress', 'paged' => FALSE ) ), 'In progress' );
return $views;
}
add_filter( 'edd_payments_table_views', 'sww_edd_payments_new_views' );
/**
* Adds bulk actions to the bulk action dropdown on "Payment History" screen
*
* @parm string[] $actions existing bulk actions
* @param string[] new bulk actions
*/
function sww_edd_bulk_status_dropdown( $actions ) {
$new_bulk_status_actions = array();
// Loop through existing bulk actions
foreach ( $actions as $key => $action ) {
$new_bulk_status_actions[ $key ] = $action;
// Add our actions after the "Set To Cancelled" action
if ( 'set-status-cancelled' === $key ) {
// Add a $new_bulk_status_actions[key] = value; for each status you've added (in the order you want)
$new_bulk_status_actions['set-status-paid'] = 'Set To Invoice Paid';
$new_bulk_status_actions['set-status-in-progress'] = 'Set To In Progress';
}
}
return $new_bulk_status_actions;
}
add_filter( 'edd_payments_table_bulk_actions', 'sww_edd_bulk_status_dropdown' );
/**
* Adds bulk actions to update orders when performed
*
* @param int $id the order ID
* @param string $action the action identifier
*/
function sww_edd_bulk_status_action( $id, $action ) {
if ( 'set-status-paid' === $action ) {
edd_update_payment_status( $id, 'invoice_paid' );
}
if ( 'set-status-in-progress' === $action ) {
edd_update_payment_status( $id, 'in_progress' );
}
}
add_action( 'edd_payments_table_do_bulk_action', 'sww_edd_bulk_status_action', 10, 2 );
/**
* Adds our custom statuses to earnings reports
*
* @param string[] $args the reporting query args
* @return string[] updated args
*/
function sww_edd_earnings_reporting_args( $args ) {
$args['post_status'] = array_merge( $args['post_status'], array( 'invoice_paid', 'in_progress' ) );
return $args;
}
add_filter( 'edd_get_earnings_by_date_args', 'sww_edd_earnings_reporting_args' );
/**
* Adds our custom statuses to sales reports
*
* @param string[] $args the reporting query args
* @return string[] updated args
*/
function sww_edd_sales_reporting_args( $args ) {
$args['post_status'] = array_merge( $args['post_status'], array( 'invoice_paid', 'in_progress' ) );
return $args;
}
add_filter( 'edd_get_sales_by_date_args', 'sww_edd_sales_reporting_args' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment