i tryed to make a code to verify the category of the product in a order when it is payed, i have tested but it dident work, i tested with credit card, but the status went to completed automatcly.
I want the order go to status "completed" when in the order have a product with the category "pack" and dont have any other diferent category, if have any other product with a different category, i want the order to go to the status "aguardando-envio".
could you help me with this?
add_action( 'woocommerce_payment_complete', function ( $order_id ) {
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
// 2. Initialize $cat_in_order variable
$cat_in_order = false;
// 3. Get order items and loop through them...
// ... if product in category, edit $cat_in_order
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ( has_term( 'videos-personalizaveis', $product_id ) ) {
$cat_in_order = true;
break;
}
if ( has_term( 'fotos-personalizaveis', $product_id ) ) {
$cat_in_order = true;
break;
}
if ( has_term( 'audios-personalizaveis', $product_id ) ) {
$cat_in_order = true;
break;
}
if ( has_term( 'produtos-pessoais', $product_id ) ) {
$cat_in_order = true;
break;
}
}
if ( $cat_in_order ) {
$order->update_status( 'aguardando-envio' );
}
if ( $cat_in_order == false ) {
$order->update_status( 'completed' );
}
}, 10, 3 );