Créer des status personnalisés pour les commandes de WooCommerce

<?php
/**
 *  WooCommerce - Order - Statuses
 *  - Custom order statuses list
 */
$custom_order_statuses = array(
    'wc-devis'       => _x( 'Devis - À traiter', 'post' ),
    'wc-precommande' => _x( 'Précommande - À traiter', 'post' ),
);
​
/**
 *  WooCommerce - Order - Status
 *  - Register custom woocommerce order statuses
 */
add_filter( 'woocommerce_register_shop_order_post_statuses', '_pit_woo_custom_post_status', 1 );
function _pit_woo_custom_post_status( $order_statuses ) {
​
    global $custom_order_statuses;
    foreach ( $custom_order_statuses as $post_status_slug => $post_status_label ) {
​
        $order_statuses[ $post_status_slug ] = array(
            'label'                     => $post_status_label,
            'public'                    => false,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( $post_status_label . ' <span class="count">(%s)</span>', $post_status_label . ' <span class="count">(%s)</span>' ),
        );
    }
​
    return $order_statuses;
}
​
/**
 *  WooCommerce - Order - Status
 *  - Add custom order status to "order" statuses
 */
add_filter( 'wc_order_statuses', '_pit_woo_custom_order_statuses' );
function _pit_woo_custom_order_statuses( $statuses ) {
​
    global $custom_order_statuses;
    foreach ( $custom_order_statuses as $post_status_slug => $post_status_label ) {
        $statuses[ $post_status_slug ] = $post_status_label;
    }
​
    return $statuses;
​
}
​
/**
 *  WooCommerce - Order - Admin
 *  - Add custom order status to "actions" order list
 */
add_filter( 'bulk_actions-edit-shop_order', '_pit_woo_custom_order_statuses_display' );
function _pit_woo_custom_order_statuses_display( $actions ) {
​
    global $custom_order_statuses;
    foreach ( $custom_order_statuses as $post_status_slug => $post_status_label ) {
​
        // Note: "mark_" must be there instead of "wc"
        $post_status_slug = str_replace( 'wc-', 'mark_', $post_status_slug );
​
        $post_status_label            = __( 'Marquer comme', 'pilot-in' ) . ' ' . $post_status_label;
        $actions[ $post_status_slug ] = $post_status_label;
​
    }
​
    return $actions;
}

/**
 *  WooCommerce - Order - Editable
 *  - Allow editing of "order" if "order" has custom status
 */
add_filter( 'wc_order_is_editable', '_pit_woo_order_editable', 10, 2 );
function _pit_woo_order_editable( $editable, $order ) {

    global $custom_order_statuses;
    if ( !$custom_order_statuses ) {
        return $editable;
    }

    $order_status = 'wc-' . $order->get_status();
    if ( !array_key_exists( $order_status, $custom_order_statuses ) ) {
        return $editable;
    }

    return true;

}

 

Modèle AARRR : comment l’appliquer à votre stratégie ?

Atelier UX : quels avantages pour votre projet ?

Combien de temps pour créer un site WordPress ?