• Resolved ehmarketing

    (@ehmarketing)


    Hi there,

    I’d like to add a column on the Product Admin page to show what Attributes each product has. Chiefly I’d like a quick and easy way to look over all the products and see any I might have forgotten to put attributes on or edit others.

    Any help on how to achieve this would be much appreciated!

Viewing 2 replies - 16 through 17 (of 17 total)
  • Hello,
    How can i add atribute quantity column in product page in admin panel and can i manage the quantity directly?

    • This reply was modified 4 years, 7 months ago by alabstlabs.
    • This reply was modified 4 years, 7 months ago by alabstlabs.

    Try the following (it worked pretty well for me, but you cant inline edit). I now got Admin Columns plugin instead, which works well to do this and allows editing and can do all the admin tables.

    
    function add_product_column( $columns ) {
        //add column
        $columns['new_column'] = __( 'New column', 'woocommerce' );
    
        return $columns;
    }
    add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 );
    
    function add_product_column_content( $column, $postid ) {
        if ( $column == 'new_column' ) {
    
            // output variable
            $output = '';
    
            // Get product object
            $product = wc_get_product( $postid );
    
            // Get Product Variations - WC_Product_Attribute Object
            $product_attributes = $product->get_attributes();
    
            // Not empty, contains values
            if ( !empty( $product_attributes ) ) {
    
                foreach ( $product_attributes as $product_attribute ) {
                    // Get name
                    $attribute_name = str_replace( 'pa_', '', $product_attribute->get_name() );
    
                    // Concatenate
                    $output = $attribute_name . ' = ';
    
                    // Get options
                    $attribute_options = $product_attribute->get_options();
    
                    // Not empty, contains values
                    if ( !empty( $attribute_options ) ) {
    
                        foreach ($attribute_options as $key => $attribute_option ) {
                            // WP_Term Object
                            $term = get_term($attribute_option); // <-- your term ID
    
                            // Not empty, contains values
                            if ( !empty( $term ) ) {
                                $term_name = $term->name;
    
                                // Not empty
                                if ( $term_name != '' ) {
    
                                    // Last loop
                                    end($attribute_options);
                                    if ( $key === key($attribute_options) ) {
                                        // Concatenate
                                        $output .= $term_name;                                  
                                    } else {
                                        // Concatenate
                                        $output .= $term_name . ', ';
                                    }
                                }
                            }
                        }
                    }
    
                    echo $output . '<br>';
                }
            }
        }
    }
    add_action( 'manage_product_posts_custom_column', 'add_product_column_content', 10, 2 );
    
Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Adding Product Attributes column to Product Admin page’ is closed to new replies.