这就是我用来创建名为“已开票”的自定义订单状态的内容。将此添加到主题的功能中。php
// New order status AFTER woo 2.2
add_action( \'init\', \'register_my_new_order_statuses\' );
function register_my_new_order_statuses() {
register_post_status( \'wc-invoiced\', array(
\'label\' => _x( \'Invoiced\', \'Order status\', \'woocommerce\' ),
\'public\' => true,
\'exclude_from_search\' => false,
\'show_in_admin_all_list\' => true,
\'show_in_admin_status_list\' => true,
\'label_count\' => _n_noop( \'Invoiced <span class="count">(%s)</span>\', \'Invoiced<span class="count">(%s)</span>\', \'woocommerce\' )
) );
}
add_filter( \'wc_order_statuses\', \'my_new_wc_order_statuses\' );
// Register in wc_order_statuses.
function my_new_wc_order_statuses( $order_statuses ) {
$order_statuses[\'wc-invoiced\'] = _x( \'Invoiced\', \'Order status\', \'woocommerce\' );
return $order_statuses;
}
为了将您的新状态添加到管理批量编辑下拉列表中,您必须使用javascript。将您的函数添加到
admin_footer
行动我的函数如下所示:
function custom_bulk_admin_footer() {
global $post_type;
if ( $post_type == \'shop_order\' ) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'<option>\').val(\'mark_invoiced\').text(\'<?php _e( \'Mark invoiced\', \'textdomain\' ); ?>\').appendTo("select[name=\'action\']");
jQuery(\'<option>\').val(\'mark_invoiced\').text(\'<?php _e( \'Mark invoiced\', \'textdomain\' ); ?>\').appendTo("select[name=\'action2\']");
});
</script>
<?php
}
}
该操作添加了两次,因为订单列表的顶部有一个批量操作,底部有另一个批量操作。