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: 0 by 0 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:

14/03/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 );

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Streamline Your Shopping with Automatic Coupon Code Integration in Your Cart

Added: 5 months ago

Last Updated: 5 months ago

Enhance your shopping experience with seamless savings! We believe in making your store user-friendly to boost order satisfaction. Say goodbye to manual coupon entries – our system now automatically a...

WooCommerce

AI Verified

0

WooCommerce Confirm Email On Registration Form

Added: 1 year ago

Last Updated: 1 year ago

This snippet generates a new custom field on the registration form which asks the user to confirm their email address (enter it a second time). By asking the user to confirm their email address, mista...

WooCommerce

AI Verified

0

WooCommerce Enable Shipping Method Based On Coupon

Added: 1 year ago

Last Updated: 1 year ago

This guide shows you how to hide a specific shipping method option and only enable it when a specific coupon code has been entered. For this to work properly, you will need to tweak the line 10 in the...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

29

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 weeks ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

9

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 5 months ago

Deactivate some WooCommerce Checkout Fields from showing

Performance

Pro Verified

5

Disable e-icons from Elementor

Added: 1 year ago

Last Updated: 1 year ago

Disable e-icons - and remove the notification from occurring during your Page Speed Insight Check.