Created
June 21, 2024 12:10
-
-
Save rwkyyy/d836e9f7afefb93b44d84510e5f4e34a to your computer and use it in GitHub Desktop.
Display stock availability for unmanaged stock in WooCommerce - Admin - Products listing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add custom column to the products admin list | |
add_filter( 'manage_edit-product_columns', 'add_custom_stock_status_column' ); | |
function add_custom_stock_status_column( $columns ) { | |
$new_columns = array(); | |
foreach ( $columns as $key => $value ) { | |
$new_columns[ $key ] = $value; | |
if ( $key === 'sku' ) { // Move after SKU column | |
$new_columns['custom_stock_status'] = 'Disponibilitate'; | |
} | |
} | |
return $new_columns; | |
} | |
// Display stock status in the custom column | |
add_action( 'manage_product_posts_custom_column', 'show_custom_stock_status_column', 10, 2 ); | |
function show_custom_stock_status_column( $column, $postid ) { | |
if ( $column === 'custom_stock_status' ) { | |
$product = wc_get_product( $postid ); | |
if ( $product->is_in_stock() ) { | |
echo '<mark class="instock">Disponibil</mark>'; | |
} elseif ( $product->is_on_backorder() ) { | |
echo '<mark class="onbackorder">Backorder</mark>'; | |
} else { | |
echo '<mark class="outofstock">Indisponibil</mark>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment