<?php

/**
 * Custom functions for Wommerce Orders
 *
 * @link       https://www.wpsaad.com
 * @since      1.0.0
 *
 * @package    ODDW
 * @subpackage ODDW/public/woocommerce
 */

/**
 * Registering Out for Delivery post status
 * 
 * @since 1.0
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

function oddw_register_out_for_delivery_order_status() {
    register_post_status( 'wc-out-for-delivery', array(
        'label'                     => __( 'Out for Delivery', 'orders-delivery-drivers-for-woocommerce' ),
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
    /* translators: %s: Number of orders out for delivery */
    'label_count'               => _n_noop( 'Out for Delivery <span class="count">(%s)</span>', 'Out for Delivery <span class="count">(%s)</span>', 'orders-delivery-drivers-for-woocommerce' )
    ) );
}
add_action( 'init', 'oddw_register_out_for_delivery_order_status' );

/**
 * Registering Driver Assigned post status
 * 
 * @since 1.0
 */
function oddw_register_driver_assigned_order_status() {
    register_post_status( 'wc-driver-assigned', array(
        'label'                     => __( 'Driver Assigned', 'orders-delivery-drivers-for-woocommerce' ),
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
    /* translators: %s: Number of orders assigned to drivers */
    'label_count'               => _n_noop( 'Driver Assigned <span class="count">(%s)</span>', 'Driver Assigned <span class="count">(%s)</span>', 'orders-delivery-drivers-for-woocommerce' )
    ) );
}
add_action( 'init', 'oddw_register_driver_assigned_order_status' );

/**
 * Add Custom Statuses to the order status list.
 *
 * @param array $order_statuses
 *
 * @return array
 * 
 * @since 1.0
 */
function oddw_add_custom_order_statuses( $order_statuses ) {

    $new_order_statuses = array();

    foreach ( $order_statuses as $key => $status ) {

        $new_order_statuses[ $key ] = $status;

        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-driver-assigned']  = __( 'Driver Assigned', 'orders-delivery-drivers-for-woocommerce' );
            $new_order_statuses['wc-out-for-delivery'] = __( 'Out for Delivery', 'orders-delivery-drivers-for-woocommerce' );
        }
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'oddw_add_custom_order_statuses' );

