Woocommerce オリジナルの手配状況・注文ステータスをPHPで追加

PHP

2月はWooCommerceとにらめっこした期間でした。

その中で、オリジナルの手配状況(注文ステータス)を追加しなければいけない状況になりました。

プラグインのYITH WooCommerce Custom Order Statusがありますが、追加したステータスが反映されないバグに遭遇。

これはfunctions.phpで追加する方が早いな・・・と思い慣れない英語を読み、functions.phpをいじり

実装できました。

スクリーンショット 2016-02-19 16.38.00

 

fuctions.phpに追加


/** 
 * Register new status
 * Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/
**/
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' );

Awaiting shipmentが名前になります。
ここを任意の名前に変更して下さい。

 

参考にしたサイト

WordPress › Error

コメント

タイトルとURLをコピーしました