Skip to content

Instantly share code, notes, and snippets.

@felipe-pita
Created May 31, 2019 14:32
Show Gist options
  • Save felipe-pita/7116132fa9ccb340da1661b5e6396de2 to your computer and use it in GitHub Desktop.
Save felipe-pita/7116132fa9ccb340da1661b5e6396de2 to your computer and use it in GitHub Desktop.
/**
* Não permitir a troca de status de pedidos cancelados.
* Muda o pedido para apovação manual
*/
add_filter( 'woocommerce_before_order_object_save', 'prevent_cancelled_order_status_change', 10, 2 );
function prevent_cancelled_order_status_change( $order, $data_store ) {
$changes = $order->get_changes();
if (isset($changes['status'])) {
$data = $order->get_data();
$from_status = $data['status'];
$to_status = $changes['status'];
if ($from_status === 'cancelled') {
$order->set_status('aprovacao-manual', 'O pedido estava cancelado e o sistema tentou alterar seu status. Favor verificar manualmente.');
}
}
return $order;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment