79319658

Date: 2024-12-31 09:55:28
Score: 2
Natty:
Report link

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?

    // Utility function: Get the custom order status by product category
function get_custom_order_status_by_cat( $order, $status = false ) {
    // Loop through order items
    foreach ( $order->get_items() as $item ) {      
        $product_id = $item->get_product_id(); // Get product ID

        if ( has_term( 'met-gravure', 'product_cat', $product_id ) ) {
            $status = 'ord-maatwerk'; // Aangepaste status
            break;
        } elseif ( has_term( 'moedermelk', 'product_cat', $product_id ) ) {
            $status = 'ord-moedermelk'; // Aangepaste status
            break;
        } elseif ( has_term( 'last-minute-gepersonaliseerd-juweel', 'product_cat', $product_id ) ) {
            $status = 'ord-lastminute'; // Aangepaste status
            break;
        }
    }
    return $status;
}


// For Mollie Payments
add_filter( 'woocommerce_payment_complete_order_status', 'update_order_status_by_category_for_mollie', 10, 3 );
function update_order_status_by_category_for_mollie(  $status, $order_id, $order  ){
    // HERE bellow, define Mollie payment method ID
    $targeted_payment_id = '*******';

    $custom_status = get_custom_order_status_by_cat( $order ); // Get custom order status
    
    // If a custom order status is found and if it's a Mollie payment
    if ( $custom_status && $order->get_payment_method() === $targeted_payment_id ) { 
        return $custom_status;
    }
    return $status;
}

Again thank you so much!

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (0.5): thank you
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Marco