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
Add a comment  | 

1 Answer 1

Reset to default 0

The 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