I’m using custom order statusses on a few product categories on our webshop.
Now that we are live I see that all orders that are "Processing" are payed with Mollie (payment GW).
However the orders that have a custom order status, and where the customer also selected Mollie, the payment GW didn’t work. The customer just gets forwarded to a next page where they see the message "Order is submitted" without the payment GW beging triggered.
The code I used:
add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ( has_term( 'met-gravure', 'product_cat', $product_id ) ) { //Categorie selecteren
$order->update_status( 'ord-maatwerk' ); // Aangepaste status
break;
} else if ( has_term( 'moedermelk', 'product_cat', $product_id ) ) { //Categorie selecteren
$order->update_status( 'ord-moedermelk' ); // Aangepaste status
break;
}
else if ( has_term( 'last-minute-gepersonaliseerd-juweel', 'product_cat', $product_id ) ) { //Categorie selecteren
$order->update_status( 'ord-lastminute' ); // Aangepaste status
break;
}
}
}
Find out what the code is to call the payment gateway but didn’t find it.
2
Answers
Thank you so much for your clear answer. Im starting to understand now (I think :-)).
If im correct the only thing I need to do is change the 'payment_id' with my Mollie ID? Do I need to include the code "// For other payment gateways than Mollie" ? Because im not using any other payment gateway. I think it will look like this?
Again thank you so much!
You should not use
woocommerce_checkout_order_processed
hook that is triggered before the payment has been processed, for orders with Mollie payment.Instead, for orders with Mollie payment, you should use
woocommerce_payment_complete_order_status
filter hook, to set the custom order statuses.Also, to avoid an error in PHP, note that the "ELSE IF" statement doesn’t include a space between
else
andif
. Instead, simply useelseif
.Try the following, defining in the both last functions the correct Mollie payment ID:
It should work, if you set in the code the correct payment ID slug for Mollie.
Some related threads using
woocommerce_payment_complete_order_status
filter hook.