3 votes

Ajout de plusieurs statuts de commande personnalisés dans Woocommerce

J'ai essayé ce code écrit ci-dessous et cela a fonctionné. Le seul problème est que j'ai besoin d'ajouter un statut supplémentaire nommé " Vérification ". Veuillez m'aider si vous pouvez le faire.

function register_awaiting_shipment_order_status() {
    register_post_status( 'wc-awaiting-shipment', array(
        'label'                     => 'Awaiting shipment',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
    ) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );
// Add to list of WC Order statuses
function add_awaiting_shipment_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-awaiting-shipment'] = 'Awaiting shipment';
        }
    }
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

3voto

LoicTheAztec Points 72349

Le code suivant, ajoutera "En attente d'expédition" y "Vérification" statuts de commande personnalisés et il remplacera le code de votre question :

add_action( 'init', 'register_custom_statuses_as_order_status' );
function register_custom_statuses_as_order_status() {

    register_post_status( 'wc-awaiting-shipment', array(
        'label'                     => __('Awaiting shipment'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
    ) );

    register_post_status( 'wc-verification', array(
        'label'                     => __('Verification'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Verification <span class="count">(%s)</span>', 'Verification <span class="count">(%s)</span>' )
    ) );
}

// Add to list of WC Order statuses
add_filter( 'wc_order_statuses', 'add_additional_custom_statuses_to_order_statuses' );
function add_additional_custom_statuses_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-awaiting-shipment'] = __('Awaiting shipment');
            $new_order_statuses['wc-verification'] = __('Verification');
        }
    }
    return $new_order_statuses;
}

Le code va dans le fichier function.php de votre thème enfant actif (thème actif). Testé et fonctionne.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X