• Resolved ohdearbambi

    (@ohdearbambi)


    Hello, I need to change the order status for orders that were purchased using wallet credit. I made a new custom order status called ‘Payment received’ using this code:

    function add_payment_received_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    foreach ( $order_statuses as $key => $status ) {
    $new_order_statuses[ $key ] = $status;
    if ( 'wc-on-hold' === $key ) {
    $new_order_statuses['wc-payment-received'] = 'Payment received';
    }
    }
    return $new_order_statuses;
    }
    add_action( 'init', 'register_payment_received_order_status' );
    add_filter( 'wc_order_statuses', 'add_payment_received_to_order_statuses' );
    

    I tried to follow this thread to change the order status but it did not seem to change anything, I still had to manually go into the order page and then change the order status. This was the code that I used:

    add_action('woo_wallet_payment_processed', 'woo_wallet_payment_processed_callback');
    if(!function_exists('woo_wallet_payment_processed_callback')){
        function woo_wallet_payment_processed_callback($order_id){
            $order = wc_get_order($order_id);
            $order->set_status('Payment received');
            $order->save();
        }
    }

    Other than that, I also tried to do so using this code:

    add_filter( 'woocommerce_wallet_process_payment_order_status', 'change_wallet_order_status', 9999, 2 );
     
    function change_wallet_order_status( $status, $order ) {
        return 'Payment received';
    }

    But similarly to the previous one, this didn’t seem to do anything. Any advice?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Subrata Mal

    (@subratamal)

    @ohdearbambi Please use the attached updated code.

    add_filter( 'woocommerce_payment_complete_order_status', 'woocommerce_payment_complete_order_status_callback', 10, 3 );
    if ( ! function_exists( 'woocommerce_payment_complete_order_status_callback' ) ) {
    	/**
    	 * Change Order status if placed with wallet.
    	 *
    	 * @param String   $status Order Status.
    	 * @param int      $order_id Order ID.
    	 * @param WC_Order $order WC Order.
    	 * @return string
    	 */
    	function woocommerce_payment_complete_order_status_callback( $status, $order_id, $order ) {
    		if ( 'wallet' === $order->get_payment_method( 'edit' ) ) {
    			$status = 'wc-payment-received';
    		}
    		return $status;
    	}
    }
    Thread Starter ohdearbambi

    (@ohdearbambi)

    Hey there!
    Works like a charm, thanks so much for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom order status for orders paid using wallet credit?’ is closed to new replies.