• Resolved delaitec

    (@delaitec)


    The “Delivery Driver” plugin displays a list of orders and their status.

    In order to change the status, it is necessary to access the orders one by one.

    I’m trying to improve this.

    On the “My Account” screen, a list of orders is displayed for the delivery person.

    I added a button, I should change the “status” of the order when clicked.

    What happens is that he is not changing the status of only the order of the clicked button, he is changing all the orders in the list.

    Does anyone know if something is wrong in my code?

    echo '<td>' . wc_get_order_status_name( $order_status );
    	if('driver-assigned' == $order_status ){
    		if(isset($_POST["outfordelivery2"])){
    			$order->update_status( 'out-for-delivery' );
    		}
    		echo '
    			<form method="post">
    			<input type="submit" value="' . esc_attr__( 'Out for Delivery', 'ddwc' ) . '" class="button ddwc-change-status" name="outfordelivery2" />
    			</form>
    		';
    	}
    	if('out-for-delivery' == $order_status ){
    		if(isset($_POST["ordercompleted2"])){
    		    $order->update_status( 'completed' );
    		}
    		echo '
    			<form method="post">
    				<input type="submit" value="' . esc_attr__( 'Completed', 'ddwc' ) . '" class="button ddwc-change-status" name="ordercompleted2" />
    			</form>
    		';
    	}
    	echo '</td>';
    • This topic was modified 4 years, 5 months ago by delaitec.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter delaitec

    (@delaitec)

    Isn’t there a function where I enter the order id and the new status to be updated?

    for example:

    update_status ($order_id, $new_status)

    like update_usermeta?

    Thread Starter delaitec

    (@delaitec)

    Solved.
    Was the order_id.

    $botao_atualiza_status = "";
    if('driver-assigned' == $order->status ){
    	if(isset($_POST["outfordelivery2"]) && $_POST["order_id"] == $order->id   ){
    		$order->update_status( 'out-for-delivery' );  // Se bot?o foi clicado e ID bate, atualiza status do ítem
    	}
    	$botao_atualiza_status = '
    		<form method="post">
    		<input type="hidden" name="order_id" value="' . $order->id . '" />
    		<input type="submit" value="' . esc_attr__( 'Out for Delivery', 'ddwc' ) . '" class="button ddwc-change-status" name="outfordelivery2" />
    		</form>
    	';
    }
    									
    	if('out-for-delivery' == $order->status ){
    		if(isset($_POST["ordercompleted2"]) && $_POST["order_id"] == $order->id ){
    			$order->update_status( 'completed' );
    		}
    		$botao_atualiza_status = '
    			<form method="post">
    			<input type="hidden" name="order_id" value="' . $order->id . '" />
    			<input type="submit" value="' . esc_attr__( 'Completed', 'ddwc' ) . '" class="button ddwc-change-status" name="ordercompleted2" />
    			</form>
    		';
    	}
    
    	echo '<td>' . wc_get_order_status_name( $order->status ) . $botao_atualiza_status . '</td>';
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘update_status doesn’t work as it should.’ is closed to new replies.