覆盖WooCommerce管理员产品列表中"is_in_stock"列中的内容



我试图覆盖列"中的内容;is_in_stock"在WooCommerce管理产品列表中。

为此,我目前使用:

<?php
add_action('manage_product_posts_custom_column', 'stock_override' );

function stock_override($column_name){
global $post;
$product = wc_get_product($post->ID);
if( $product->is_type('variable')){
if ($column_name == 'is_in_stock') {
echo 'own text';
}
}
}
?>

但这并没有覆盖默认内容,而是将我的文本添加到其中。默认内容为库存状态onstockbackorderout of stock

我创建了一个自定义产品类型,如果产品类型等于variable,我希望覆盖is_in_stock列中的内容。如果不相等,请从WooCommerce中回声默认值。

我可以删除整个列并添加我自己的列,但如果producttype不相等,我就没有默认内容。

谁能帮我一点忙?

无需删除默认列并将其替换为新列,只需使用woocommerce_admin_stock_html过滤器即可访问$product对象。

这样,您就可以将自己的文本/状态添加到现有列中。

所以你得到了:

// Admin product list: is_in_stock
function filter_woocommerce_admin_stock_html( $stock_html, $product ) {
// Condition
if ( $product->is_type('variable') ) {
$stock_html = '<mark class="someclass" style="background:transparent none; color:#33ccff; font-weight:700; line-height:1;">' . __( 'My text', 'woocommerce' ) . '</mark>';      
}
return $stock_html;
}
add_filter( 'woocommerce_admin_stock_html', 'filter_woocommerce_admin_stock_html', 10, 2 );

相关内容

最新更新