Forked from bekarice/edd-custom-payment-statuses.php
Created
December 20, 2015 14:14
-
-
Save Basilakis/ece115088ae06d16b427 to your computer and use it in GitHub Desktop.
Add custom EDD payment statuses
This file contains hidden or 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
/** | |
* Adds new payment statuses to array of available 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 | |
*/ | |
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 | |
*/ | |
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 ) { | |
$new_bulk_status_actions['set-status-paid'] = 'Set To Invoice Paid'; | |
$new_bulk_status_actions['set-status-in-progress'] = 'Set To In Progress'; | |
// Add a $new_bulk_status_actions[key] = value; for each status you've added (in the order you want) | |
} | |
} | |
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 | |
*/ | |
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 and sales reports | |
*/ | |
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' ); | |
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