, meta_key _stock_status, _stock parse_query, restrict_manage_posts instock outofstock. woocommerce, , .
<?php
add_action( 'restrict_manage_posts', 'wpse45436_admin_posts_filter_restrict_manage_posts' );
function wpse45436_admin_posts_filter_restrict_manage_posts(){
$type = 'product';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if ('product' == $type){
$values = array(
'Out of Stock' => 'outofstock',
'In Stock' => 'instock',
);
?>
<select name="Stock">
<option value=""><?php _e('Show All Stock', 'wpse45436'); ?></option>
<?php
$current_v = isset($_GET['Stock'])? $_GET['Stock']:'';
foreach ($values as $label => $value) {
printf
(
'<option value="%s"%s>%s</option>',
$value,
$value == $current_v? ' selected="selected"':'',
$label
);
}
?>
</select>
<?php
}
}
add_filter( 'parse_query', 'wpse45436_posts_filter' );
function wpse45436_posts_filter( $query ){
global $pagenow;
$type = 'product';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if ( 'product' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['Stock']) && $_GET['Stock'] != '') {
$query->query_vars['meta_key'] = '_stock_status';
$query->query_vars['meta_value'] = $_GET['Stock'];
}
}