1. Home
  2. Docs
  3. Pick List
  4. Settings
  5. Custom Product Fields (Add by hook – custom code)

Custom Product Fields (Add by hook – custom code)

In this guide, we will show you how to add custom product fields to Pick List for WooCommerce’s order items (Pick Order Tab) using a hook in your WordPress site. We’ll use the popular Snippets plugin to safely add custom code without directly editing your functions.php file.

Why use code to add custom product fields? If you have a lot of custom product fields that you want to use in the pick list (more than 4 as you can set up in settings) – then this will help you manage that.

Why Use the Snippets Plugin?

The Snippets plugin provides a safe and user-friendly way to add custom PHP code to your site. You can:

  • Enable/disable snippets without breaking your site.
  • Organize and label snippets for better management.
  • Avoid directly editing the functions.php file, which can cause issues if done incorrectly.

Step-by-Step Guide

1. Install and Activate the Snippets Plugin

  1. Go to your WordPress admin dashboard.
  2. Navigate to Plugins > Add New.
  3. Search for “Code Snippets“.
  4. Click Install Now, then Activate.

2. Create a New Snippet

  1. Navigate to Snippets > Add New in the WordPress dashboard.
  2. Enter a title for your snippet, such as "Add Custom Product Fields to Pick Order Tab".
  3. Paste the following example code into the code editor (change names and slugs to fit your custom product fields):
add_filter( 'cas_picklist_custom_product_fields', function( $custom_fields ) {

// Add custom fields in an associative array format
$custom_fields[] = [
'name' => 'Warehouse Location',
'slug' => 'warehouse_location',
'use' => 'yes',
];

$custom_fields[] = [
'name' => 'Warranty',
'slug' => 'warranty',
'use' => 'yes',
];

return $custom_fields;
});
  1. Name = your label for this field, Slug = slug / custom field name, Use = ‘yes’ means to activate it and ‘no’ means to deactivate it.
  2. Save the snippet and enable it by toggling the “Activate” switch. (PS use only Admin area – see example below)

3. Verify the Custom Fields

  1. Go to your WooCommerce order details page and verify that the custom fields (e.g. Warehouse Location and Warranty) are available in the relevant sections.
  2. If you encounter issues, disable the snippet in Snippets > All Snippets for troubleshooting.

Example Screenshot

Here’s an example of adding a new snippet using the Snippets plugin:

Benefits of Using Snippets for Custom Fields

  • Safe and Organized: Avoids breaking your site by separating code changes into manageable snippets.
  • Easy to Manage: Enables or disables snippets without needing to edit the functions.php file directly.
  • Extend Functionality: Allows you to easily extend your WooCommerce store without technical risk.

Notes

  1. Always test new code snippets in a staging environment before deploying to your live site.
  2. If you’re unsure about any custom fields, consult your WooCommerce documentation or developer.

How can we help?