Created
December 24, 2025 04:25
-
-
Save rajeshsingh520/6b0c1a72c1d6e88c29aecd25b4c95790 to your computer and use it in GitHub Desktop.
store credit with germanize
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
| class pisol_acblw_germanize{ | |
| static $instance = null; | |
| public static function get_instance(){ | |
| if(self::$instance == null){ | |
| self::$instance = new self(); | |
| } | |
| return self::$instance; | |
| } | |
| function __construct(){ | |
| add_filter('acblw_total_discount_given', [$this, 'total_discount_given'], 10, 4); | |
| add_action('acblw_store_credit_refund_completed', [$this, 'reset_coupon_used_amount'], 10, 4); | |
| } | |
| function total_discount_given($total_discount, $orders_id, $coupon_id, $excluded_order_id){ | |
| // If the coupon is marked as a voucher, don't count its discounts. | |
| $coupon = new WC_Coupon( $coupon_id ); | |
| $is_voucher = $coupon->get_meta( 'is_voucher' ); | |
| if ( empty( $is_voucher ) ) { | |
| return $total_discount; | |
| } | |
| if(empty($orders_id)) return 0; | |
| if(!is_array($orders_id)) return 0; | |
| if(in_array($excluded_order_id, $orders_id)){ | |
| $key = array_search($excluded_order_id, $orders_id); | |
| unset($orders_id[$key]); | |
| } | |
| $total_discount = 0; | |
| $coupon_code = get_the_title( $coupon_id ); | |
| foreach ( $orders_id as $order_id ) { | |
| $order = wc_get_order( $order_id ); | |
| if ( ! $order ) { | |
| continue; | |
| } | |
| $status = $order->get_status(); | |
| if ( in_array( $status, array( 'trash', 'refunded', 'cancelled', 'failed', 'checkout-draft' ) ) ) { | |
| continue; | |
| } | |
| $fees = $order->get_fees(); | |
| foreach ( $fees as $fee ) { | |
| if ( strpos( strtolower( $fee->get_name() ), strtolower( $coupon_code ) ) !== false ) { | |
| $total_discount += abs( $fee->get_total() ); | |
| } | |
| } | |
| } | |
| return $total_discount; | |
| } | |
| function reset_coupon_used_amount($order, $refund_amount, $coupon_code, $id ){ | |
| $coupon = new WC_Coupon( $id ); | |
| $coupon->update_meta_data( 'is_voucher', 'yes' ); | |
| $coupon->save(); | |
| } | |
| } | |
| pisol_acblw_germanize::get_instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment