I am using Woocommerce with WCMP (WC Markeplace), however vendors are not allowed to update the order status (i.e.: from 'processing' to 'completed').
There's no option in their backend, so I tryed to add a custom button to handle that!
Any help would be amazing! Here's my code (I found it somewhere around here):
<form method="post">
<input type="hidden" name="mark_as_received" value="true">
<input type="hidden" name="order_id" value="<?php echo esc_attr($order_id);?>">
<?php wp_nonce_field( 'so_38792085_nonce_action', '_so_38792085_nonce_field' ); ?>
<input type="submit" value="I Got It!">
</form>
And to handle the form:
<?php
add_action( 'wp_loaded', 'custom_button_to_update' );
function custom_button_to_update(){
// not a "mark as received" form submission
if ( ! isset( $_POST['mark_as_received'] ) ){
return;
}
// basic security check
if ( ! isset( $_POST['_so_38792085_nonce_field'] ) || ! wp_verify_nonce( $_POST['_so_38792085_nonce_field'], 'so_38792085_nonce_action' ) ) {
return;
}
// make sure order id is submitted
if ( ! isset( $_POST['order_id'] ) ){
$order_id = intval( $_POST['order_id'] );
$order = wc_get_order( $order_id );
$order->update_status( "completed" );
return;
}
else {
echo "failed";
}
}
Thank you for your help in advance!