AI Verified

Name

Add WooCommerce Product Type as Admin Column

About

Make it easier to spot if a Product is a Simple or Variable Product.

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:

Potential vulnerability found : Cross Site Scripting
Found on line : 23
Code : echo(ucfirst($product->get_type()
Vulnerable line : 18
Code : $product = wc_get_product($postid));

Found 1 vulnerabilities

Add WooCommerce Product Type as Admin Column

 
                    
1// Add a new column for 'Product Type' to the Products page in the admin dashboard
2function add_product_type_column($columns) {
3 // Insert the 'Product Type' column after the 'name' column
4 $new_columns = [];
5 foreach ($columns as $key => $title) {
6 $new_columns[$key] = $title;
7 if ('name' === $key) {
8 $new_columns['product_type'] = __('Product Type', 'your-text-domain');
9 }
10 }
11 return $new_columns;
12}
13add_filter('manage_edit-product_columns', 'add_product_type_column', 10, 1);
14 
15// Populate the 'Product Type' column with the type of the product
16function show_product_type_in_column($column, $postid) {
17 if ($column == 'product_type') {
18 $product = wc_get_product($postid);
19 if (!$product) {
20 echo __('N/A', 'your-text-domain'); // Display N/A if product is not found
21 return;
22 }
23 // Display the product type
24 echo ucfirst($product->get_type()); // Capitalize the first letter
25 }
26}
27add_action('manage_product_posts_custom_column', 'show_product_type_in_column', 10, 2);
28 
29// Custom CSS to adjust the width of the 'Product Type' column to 15%
30function custom_admin_column_widths() {
31 echo '<style>
32 .wp-list-table .column-product_type { width: 6% !important; }
33 </style>';
34}
35add_action('admin_head', 'custom_admin_column_widths');

1

Comments

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Clear Woo Cart after 5 mins

Added: 5 months ago

Last Updated: 5 months ago

This will clear the Woo Cart after 5 mins of inactivity

WooCommerce

AI Verified

0

Add Inline Field Error Notifications @ WooCommerce Checkout

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Show Number Of Units Sold On Product Archive

Added: 1 year ago

Last Updated: 1 year ago

Showing the number of units sold for products on the archive page is a great way to introduce Fear Of Missing Out (FOMO). It also gives your customers an indication of the most popular products in you...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

31

Remove Unused Javascript

Added: 1 year ago

Last Updated: 4 weeks 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 days ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 7 months ago

Last Updated: 1 month ago

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