AI Verified

Name

Add WooCommerce Attributes as Admin Column

About

When. you're using Attributes, make it easier to see if any are active from your Products Dashboard.

Language

PHP

Rating

Voted: 1 by 1 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

10/05/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Add WooCommerce Attributes as Admin Column

 
                    
1function add_product_attributes_column( $columns ) {
2 // Add a new column for attributes after the 'name' column
3 $new_columns = array();
4 foreach ( $columns as $key => $title ) {
5 $new_columns[ $key ] = $title;
6 if ( 'name' === $key ) {
7 $new_columns['product_attributes'] = __( 'Attributes', 'your-text-domain' );
8 }
9 }
10 return $new_columns;
11}
12add_filter( 'manage_edit-product_columns', 'add_product_attributes_column', 10, 1 );
13 
14// Populate the custom column with product attributes
15function show_product_attributes_in_column( $column, $postid ) {
16 if ( $column == 'product_attributes' ) {
17 global $product;
18 // Ensure we have a product object
19 if ( !is_a( $product, 'WC_Product' ) ) {
20 $product = wc_get_product( $postid );
21 }
22 
23 if ( ! $product ) {
24 echo '';
25 return;
26 }
27 
28 // Get the product attributes
29 $attributes = $product->get_attributes();
30 
31 if ( !empty( $attributes ) ) {
32 $attributes_list = array();
33 foreach ( $attributes as $attribute ) {
34 // If the attribute is a taxonomy
35 if ( $attribute->is_taxonomy() ) {
36 $values = wc_get_product_terms( $product->get_id(), $attribute->get_name(), array( 'fields' => 'names' ) );
37 $attributes_list[] = wc_attribute_label( $attribute->get_name() ) . ': ' . join( ', ', $values );
38 } else {
39 // For custom product attributes
40 $attributes_list[] = wc_attribute_label( $attribute->get_name() ) . ': ' . $attribute->get_options();
41 }
42 }
43 echo join( ', ', $attributes_list );
44 } else {
45 echo __( 'No attributes', 'your-text-domain' );
46 }
47 }
48}
49add_action( 'manage_product_posts_custom_column', 'show_product_attributes_in_column', 10, 2 );

1

Comments

  • MM

    2 months ago

    Seeing the attributes right there is very helpful

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Show Product-Specific Content Under Loop Item Title

Added: 1 year ago

Last Updated: 1 year ago

Do you want to be able to display product specific information under the title and above the price on the loop item which appears on the product archive page? Maybe you want to let customers know of s...

WooCommerce

AI Verified

0

Show Order Histories on User Profiles at the Backend

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Display Prices With + Without Tax

Added: 1 year ago

Last Updated: 1 year ago

This code snippet is a part of a WordPress plugin or theme customization that modifies the display of prices in the WooCommerce plugin, specifically the suffix that appears after the product price....

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.