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

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');

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Display Prices With + Without Tax

Added: 10 months ago

Last Updated: 10 months 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....

WooCommerce

Unverified

0

Customize css "Apply Coupon" button in Woocommerce

Added: 1 year ago

Last Updated: 1 year ago

Make customize CSS "Apply Coupon" button in your Woocommerce Cart page.

WooCommerce

AI Verified

0

Disable Payment Method for Specific Category

Added: 1 year ago

Last Updated: 1 year ago

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.