Skip Navigation

[Gelöst] How to add wpcf custom field to woocommerce products table

This support ticket is created vor 2 Jahre, 2 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 Antworten, has 2 Stimmen.

Last updated by Luo Yang vor 2 Jahre, 2 Monate.

Assisted by: Luo Yang.

Author
Artikel
#2295925

I have created a custom field for woo products. It's a Toolset radio button field.

my field slug is "art-sold-status"

How can I add that field as a column to the Woo Products table?
Screenshot : hidden link

I found a tutorial online but don't know how to adapt the code to work with the toolset custom field.
Online tutorial: hidden link

Can you help, please?

#2296315

Hello,

I assume the custom field "art-sold-status" is created with Toolset Types plugin, Types plugin will add prefix "wpcf-" before field slug, so in your custom PHP codes, you need to use field slug "wpcf-art-sold-status", for example:

get_post_meta( $product_id, 'wpcf-art-sold-status', true);

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/

when you are accessing custom fields through native WordPress functions, you need to prepend the wpcf- prefix to the slug. Continuing from the above example, for native WordPress function to access the “House Price” field, you need to use the wpcf-house-price slug.

#2296589

Thanks for confirming the wpcf- part, Luo.

Would you be able to provide me a snippet to use in my website to add a new column for “art sold status” to the woo products page?

#2298319

For example:

add_filter( 'manage_edit-product_columns', 'bbloomer_admin_products_visibility_column', 9999 );
 
function bbloomer_admin_products_visibility_column( $columns ){
   $columns['art-sold-status'] = 'art-sold-status';
   return $columns;
}
 
add_action( 'manage_product_posts_custom_column', 'bbloomer_admin_products_visibility_column_content', 10, 2 );
 
function bbloomer_admin_products_visibility_column_content( $column, $product_id ){
    if ( $column == 'art-sold-status' ) {
        $product = wc_get_product( $product_id );
      echo get_post_meta( $product_id, 'wpcf-art-sold-status', true);
    }
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.