admin管理员组文章数量:1122846
I've searched and searched but have not been able to find an answer to this, so thank you in advance for your help!
I am wanting to display a list (in the Admin portal, on the Products page) of all products that do NOT have a specific attribute assigned (so we can easily find products that need to be updated).
I have the same functionality already set up to display products that are missing other criteria (shipping class, weight, etc.) using a variation of this code and it works great, but I am not sure how to modify it to display products without the pa_sort-chassis attribute... so far, this is what I've got - it doesn't produce any results, though.
add_action( 'admin_notices', 'products_no_chassisattribute_admin' );
function products_no_chassisattribute_admin(){
global $pagenow, $typenow;
if ( 'edit.php' === $pagenow && 'product' === $typenow ) {
echo '<div class="notice notice-warning is-dismissible"><h3>Products with NO Sort By Chassis Attribute</h3><ul>';
$args = array(
'status' => 'publish',
'visibility' => 'visible',
'limit' => -1
);
$products = wc_get_products( $args );
foreach ( $products as $product ) {
if ( ! $product = wc_get_products( array( 'pa_sort-chassis' => '' ) )) {
echo '<li><a href="' . esc_url( get_edit_post_link( $product->get_id() ) ) . '">' . $product->get_name() . '</a></li>';
}
}
echo '</ul></div>';
}
I've searched and searched but have not been able to find an answer to this, so thank you in advance for your help!
I am wanting to display a list (in the Admin portal, on the Products page) of all products that do NOT have a specific attribute assigned (so we can easily find products that need to be updated).
I have the same functionality already set up to display products that are missing other criteria (shipping class, weight, etc.) using a variation of this code and it works great, but I am not sure how to modify it to display products without the pa_sort-chassis attribute... so far, this is what I've got - it doesn't produce any results, though.
add_action( 'admin_notices', 'products_no_chassisattribute_admin' );
function products_no_chassisattribute_admin(){
global $pagenow, $typenow;
if ( 'edit.php' === $pagenow && 'product' === $typenow ) {
echo '<div class="notice notice-warning is-dismissible"><h3>Products with NO Sort By Chassis Attribute</h3><ul>';
$args = array(
'status' => 'publish',
'visibility' => 'visible',
'limit' => -1
);
$products = wc_get_products( $args );
foreach ( $products as $product ) {
if ( ! $product = wc_get_products( array( 'pa_sort-chassis' => '' ) )) {
echo '<li><a href="' . esc_url( get_edit_post_link( $product->get_id() ) ) . '">' . $product->get_name() . '</a></li>';
}
}
echo '</ul></div>';
}
Share
Improve this question
asked Mar 14, 2024 at 23:07
Augusta J.Augusta J.
111 bronze badge
1 Answer
Reset to default 0The Admin Columns Pro plugin would let you do this without any custom code. You would modify the 'All Products' list screen by adding a column for the attribute in question. Then you would filter the list for all products for which the pa_sort-chassis is not set.
This plugin is indispensible, especially for WooCommerce admin screens.
The plugin also supports inline editing from the list screen as well as BULK editing from the list screen.
本文标签: woocommerce offtopicDisplay List of Products With Missing Attribute
版权声明:本文标题:woocommerce offtopic - Display List of Products With Missing Attribute? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311652a1934816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论