Looking through the woocommerce-points-and-rewards file structure I found:
public function __construct() {
...more
// credit points back to the user if their order is cancelled or refunded
add_action( 'woocommerce_order_status_cancelled', array( $this, 'handle_cancelled_refunded_order' ) );
add_action( 'woocommerce_order_status_refunded', array( $this, 'handle_cancelled_refunded_order' ) );
}
I see the add_action of woocommerce_order_status_cancelled.
Here’s the function it calls:
public function handle_cancelled_refunded_order( $order_id ) {
global $wc_points_rewards;
$order = new WC_Order( $order_id );
// bail for guest user
if ( ! $order->user_id )
return;
// handle removing any points earned for the order
$points_earned = get_post_meta( $order->id, '_wc_points_earned', true );
if ( $points_earned > 0 ) {
// remove points
WC_Points_Rewards_Manager::decrease_points( $order->user_id, $points_earned, 'order-cancelled', null, $order->id );
// remove points from order
delete_post_meta( $order->id, '_wc_points_earned' );
// add order note
$order->add_order_note( sprintf( __( '%d %s removed.', 'wc_points_rewards' ), $points_earned, $wc_points_rewards->get_points_label( $points_earned ) ) );
}
// handle crediting points redeemed for a discount
$points_redeemed = get_post_meta( $order->id, '_wc_points_redeemed', true );
if ( $points_redeemed > 0 ) {
// credit points
WC_Points_Rewards_Manager::increase_points( $order->user_id, $points_redeemed, 'order-cancelled', null, $order->id );
// remove points from order
delete_post_meta( $order->id, '_wc_points_redeemed' );
// add order note
$order->add_order_note( sprintf( __( '%d %s credited back to customer.', 'wc_points_rewards' ), $points_redeemed, $wc_points_rewards->get_points_label( $points_redeemed ) ) );
}
}
I trace the code and find out that I don’t see the correct records being updated. Is it possible this part of the plugin is broken? I wish I could use debug bar or some debugging options but my site breaks when installing the popular debug bar. wp_debug is set to true and I get nothing.