Public Ticket #2964755

How to know if agent/customer created order?

Closed
Comments
19 Tickets 1
Mervin started the conversation 5 years ago on January 24, 2022 at 8:57am

Hi,

Is there a way I can pull a custom_field that will tell me if order was done via agent or customer himself?

I can accept answers as:
- true/false (order via agent)
- agent name (if agent made order, otherwise empty)

2,762
KingsPlugins replied 5 years ago on January 24, 2022 at 11:42am

Hi Mervin,

Actually, yes, each order has a "salesking_order_placed_type" (order meta key) custom field:

2655526157.png

This can have the value of "placed_by_customer" or "placed_by_agent".



19 Tickets 1
Mervin replied 5 years ago on January 24, 2022 at 12:20pm

Cool, thanks.

Do you know of a way/custom code that would put following orders:

salesking_order_placed_type = placed_by_customer
as a custom order status? For example: on hold, or a custom one: under review

2,762
KingsPlugins replied 5 years ago on January 24, 2022 at 4:07pm

I think you'd need to add this code to define your new order status first:

add_action('init', function(){
    register_post_status( 'wc-newstatus', array(
        'label'        => 'New Status',
        'public'    => true,
        'show_in_admin_all_list'    => false,
        'show_in_admin_status_list' => true, // show count All (12) , Completed (9) , Credit purchase (2) ...
        'label_count'    => _n_noop( 'New status order (%s)', 'New status order (%s)' )
    ) );
});

Then this code to set the status when an order is placed by customer:

add_action( 'woocommerce_checkout_order_processed', function($order_id, $posted_data, $order){
    $placed_by = get_post_meta($order_id,'salesking_order_placed_type', true);
    if ($placed_by === 'placed_by_customer'){
        $order->update_status('wc-newstatus');
        $order->save();
    }
}, 100, 3);

Sign In