Automatic tracking import and auto order status update

Should AliDropship add the feature to schedule automatic tracking import and order status updates?

  • No, I don't need this

    Votes: 0 0.0%
  • Yes but only the automatic tracking import

    Votes: 0 0.0%
  • Yes but only the automatic order status update when an order is shipped

    Votes: 0 0.0%

  • Total voters
    4

the_lyall

Active Member
For me, I would really like to see the feature to schedule automated tracking imports (to run daily at a time I choose) and, more importantly, the ability to select an order status to automatically change the order to once the tracking has been added to an order. For example, change the status of the order from 'Processing' to 'Shipped' automatically when the tracking has been imported for all lines rather than having to update all orders manually. It can be based off the same trigger which sends the tracking email, as that is also only sent once all order lines have a tracking number. If the tracking email is sent for an order update the order status to X status.

The order status update I already asked for in an email and has apparently been asked to the developers, but it's unlikely it will happen as it's just my idea.

I would like to take a poll here of who would find it useful to add the ability to schedule automatic tracking imports and also automatically update order statuses once tracking has been added. If there are lots of people who want this, it might be more likely to get added to a future release rather than just one person asking for it.

Thanks
 

Enov

Active Member
"For example, change the status of the order from 'Processing' to 'Shipped' automatically when the tracking has been imported for all lines rather than having to update all orders manually "

I'm looking for this feature as well, I think possible to do it in a hook in functions.php
 

the_lyall

Active Member
"For example, change the status of the order from 'Processing' to 'Shipped' automatically when the tracking has been imported for all lines rather than having to update all orders manually "

I'm looking for this feature as well, I think possible to do it in a hook in functions.php

That's what I would do, but the plugin files are ioncube loader encrypted so I can't see what to hook into. I haven't got round to decrypting them yet, but it should be relatively simple to add in.

Please can you add your vote to the poll at the top of the page?
 

Enov

Active Member
Here we go, I coded this quickly, I hope it's helpfull!

PHP:
// Mark all fully shipped orders to completed
add_action( 'init', 'auto_update_orders_status_from_processing_to_completed' );
function auto_update_orders_status_from_processing_to_completed(){
    $processing_orders = wc_get_orders( $args = array(
        'numberposts' => -1,
        'post_status' => 'wc-processing',
    ) );
    if(!empty($processing_orders)){
        foreach($processing_orders as $order){
            $all_shipped=true;
            foreach ( $order->get_items() as $item_id => $item ) {
                $tracking_number = wc_get_order_item_meta( $item_id, 'adsw_tip' );
                if(empty($tracking_number)){
                    $all_shipped=false;
                }
            }
            if($all_shipped){
                $order->update_status( 'completed' );
            }
        }
    }
}


Add this to functions.php, it will loop all processing orders, check if all items are shipped, if yes = order will be marked completed.
If someone can improve it, to make it run one time daily.
 

the_lyall

Active Member
Here we go, I coded this quickly, I hope it's helpfull!

PHP:
// Mark all fully shipped orders to completed
add_action( 'init', 'auto_update_orders_status_from_processing_to_completed' );
function auto_update_orders_status_from_processing_to_completed(){
    $processing_orders = wc_get_orders( $args = array(
        'numberposts' => -1,
        'post_status' => 'wc-processing',
    ) );
    if(!empty($processing_orders)){
        foreach($processing_orders as $order){
            $all_shipped=true;
            foreach ( $order->get_items() as $item_id => $item ) {
                $tracking_number = wc_get_order_item_meta( $item_id, 'adsw_tip' );
                if(empty($tracking_number)){
                    $all_shipped=false;
                }
            }
            if($all_shipped){
                $order->update_status( 'completed' );
            }
        }
    }
}


Add this to functions.php, it will loop all processing orders, check if all items are shipped, if yes = order will be marked completed.
If someone can improve it, to make it run one time daily.

Nice!

I believe you can use a custom interval in wp_schedule_event(), I found this example:

PHP:
function myprefix_custom_cron_schedule( $schedules ) {
    $schedules['every_six_hours'] = array(
        'interval' => 21600, // Every 6 hours
        'display'  => __( 'Every 6 hours' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );

//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) {
    wp_schedule_event( time(), 'every_six_hours', 'myprefix_cron_hook' );
}

///Hook into that action that'll fire every six hours
add_action( 'myprefix_cron_hook', 'myprefix_cron_function' );

//create your function, that runs on cron
function myprefix_cron_function() {
    //your function...
}

Ideally we would be able to schedule the tracking import to run at the same time (or just before) so there is no delay between the two.
 

the_lyall

Active Member
Can also set to specific time apparently:

PHP:
wp_schedule_event( strtotime('16:20:00'), 'daily', 'myprefix_cron_hook' );

For your function without a schedule, does it run constantly or is it triggered by something?
 
Top