Display the SKU for WooCommerce products within re-order interface

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

The Advanced Post Types Order plugin is a powerful tool that allows WooCommerce store owners to easily and accurately sort products within categories. One of the standout features of this plugin is its ability to maintain the order of products across multiple categories, ensuring a consistent shopping experience for customers.

By default, the re-order interface in WooCommerce displays a product’s thumbnail, title, and object ID. However, many store owners may find it useful to include additional product details in this interface to better manage their inventory. One such detail is the SKU (Stock Keeping Unit), a unique identifier for each product. With a simple customization, you can display the SKU directly within the re-order interface.

How to Display the SKU in the Re-order Interface

To add the SKU to the re-order interface, you’ll need to use a custom filter provided by the Advanced Post Types Order plugin. The following code snippet demonstrates how to achieve this:

    add_filter('apto/reorder_item_additional_details', '_apto_reorder_item_additional_details', 10, 2); 
    function  _apto_reorder_item_additional_details( $item_additional_details, $post_data )
    {
        
        //we need that only for products
        if( $post_data->post_type   !=  'product' )
            return $item_additional_details;    
        
        //retirve the custom field 
        $custom_field_value = get_post_meta($post_data->ID, '_sku', TRUE);
        
        if( ! empty( $custom_field_value ) )
            {
                
                $item_additional_details .=  ' <small>SKU : <b>' . $custom_field_value . '</b></small>';
                
            }

        return $item_additional_details;
    }

Explanation of the Code

  1. Filter Hook: The add_filter function hooks into the apto/reorder_item_additional_details filter, allowing us to modify the additional details displayed in the re-order interface.
  2. Function Definition: The _apto_reorder_item_additional_details function is defined to process the additional details for each item.
  3. Product Check: We first check if the current item is a WooCommerce product by verifying its post_type. If it’s not a product, the function returns the existing additional details without modification.
  4. SKU Retrieval: If the item is a product, we retrieve the SKU using the get_post_meta function, which fetches the _sku meta field value associated with the product.
  5. Append SKU: If the SKU is available, it is appended to the additional details in a formatted manner (e.g., “SKU: 12345”).
  6. Return Statement: Finally, the modified additional details are returned and displayed in the re-order interface.

Visual Output

Once the code is implemented, the SKU will appear in the re-order interface, as shown below:

Benefits of Displaying SKU in the Re-order Interface

  1. Enhanced Inventory Management: Store managers can quickly identify products by their SKU, streamlining the reordering process.
  2. Avoiding Confusion: SKUs are unique identifiers, reducing the risk of confusion between similar product names or variations.
  3. Improved Workflow: The additional SKU information can significantly improve the efficiency of managing large inventories, especially for stores with extensive product catalogs.

Using the Advanced Post Types Order plugin, you can easily extend the WooCommerce re-order interface to include additional information such as SKUs. This small but impactful customization can lead to better product management and a more organized workflow. Implementing the above code is a straightforward way to enhance your WooCommerce store’s backend functionality, making inventory management more intuitive and efficient.

For more advanced customizations or support, refer to the Advanced Post Types Order API documentation.