Last active
February 16, 2016 03:49
-
-
Save cklosowski/a36607655301c2af9b64 to your computer and use it in GitHub Desktop.
Examples for using the EDD_Payment->refund() refund method
This file contains 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
<?php | |
/** | |
* Enable processing refunds on payments where the old status as NOT completed or revoked | |
* | |
* Default: false | |
*/ | |
function ck_maybe_refund_payment( $maybe_refund, $payment ) { | |
if ( 'my_custom_post_status' === $payment->old_status ) { | |
$maybe_refund = true; | |
} | |
return $maybe_refund; | |
} | |
add_filter( 'edd_should_process_refund', 'ck_maybe_refund_payment', 10, 2 ); | |
/** | |
* Allow developers to choose whether or not to decrease store earnings when refunding | |
* | |
* Default: true | |
*/ | |
function ck_maybe_decrease_store_earnings( $decrease_earnings, $payment ) { | |
if ( ! empty( $payment->parent_payment ) && 'refunded' === $payment->status ) { | |
$decrease_earnings = false; | |
} | |
return $decrease_earnings; | |
} | |
add_filter( 'edd_decrease_store_earnings_on_refund', 'ck_maybe_decrease_store_earnings', 10, 2 ); | |
/************************** | |
* Download Stats Filters * | |
**************************/ | |
/** | |
* Allows developers to choose whether or not to decrease the sales count of a download | |
* | |
* Default: true | |
*/ | |
function ck_maybe_decrease_download_sales( $decrease_sales, $payment ) { | |
if ( ! empty( $payment->parent_payment ) && 'refunded' === $payment->status ) { | |
$decrease_sales = false; | |
} | |
return $decrease_sales; | |
} | |
add_filter( 'edd_decrease_sales_on_undo', 'ck_maybe_decrease_download_sales', 10, 2 ); | |
/** | |
* Allows developers to choose whether or not to decrease the earnings of a download | |
* | |
* Default: true | |
*/ | |
function ck_maybe_decrease_download_earnings( $decrease_earnings, $payment ) { | |
if ( ! empty( $payment->parent_payment ) && 'refunded' === $payment->status ) { | |
$decrease_earnings = false; | |
} | |
return $decrease_earnings; | |
} | |
add_filter( 'edd_decrease_earnings_on_undo', 'ck_maybe_decrease_download_earnings', 10, 2 ); | |
/************************** | |
* Customer Stats Filters * | |
**************************/ | |
/** | |
* Allows developers to choose whether or not to decrease the sales count of a customer | |
* | |
* Default: true | |
*/ | |
function ck_maybe_decrease_customer_sales( $decrease_purchases, $payment ) { | |
if ( ! empty( $payment->parent_payment ) && 'refunded' === $payment->status ) { | |
$decrease_purchases = false; | |
} | |
return $decrease_purchases; | |
} | |
add_filter( 'edd_decrease_customer_purchase_count_on_refund', 'ck_maybe_decrease_customer_sales', 10, 2 ); | |
/** | |
* Allows developers to choose whether or not to decrease the purchase value of a customer | |
* | |
* Default: true | |
*/ | |
function ck_maybe_decrease_customer_value( $decrease_value, $payment ) { | |
if ( ! empty( $payment->parent_payment ) && 'refunded' === $payment->status ) { | |
$decrease_value = false; | |
} | |
return $decrease_value; | |
} | |
add_filter( 'edd_decrease_customer_value_on_refund', 'ck_maybe_decrease_customer_value', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment