Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Fryvisuals

    (@fryvisuals)

    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.

    Thread Starter Fryvisuals

    (@fryvisuals)

    When trashing (move to trash – bulk option) an order via the dashboard screen for woocommerce, the points are not deducted. Points are deducted if the admin cancels the order by viewing the order and changing order status to cancelled. I feel there should be a deduction as well if the order is trashed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Admin deletion of Order does not deduct points from user’ is closed to new replies.