Custom Per Product Units for WooCommerce Documentation





WooCommerce Custom Per Product Units Documentation




Overview

Custom Per Product Units for WooCommerce is a versatile plugin that lets you display product dimensions and weight in custom units on a per-product basis. This tool allows you to meet regional measurement standards and enhance the customer experience. Moreover, it easily overrides WooCommerce’s default settings. In short, our plugin ensures every product listing meets your specific market needs and improves conversion rates.

Key Features

  • Custom Weight Units: Choose from a wide range of weight measurements such as kilograms, grams, pounds, and ounces.
  • Custom Dimension Units: Select from various dimension units like meters, centimeters, inches, feet, and yards.
  • Admin Preview: Enjoy a live preview that instantly shows how your custom unit selections will appear on the front end.
  • Easy Integration: Seamlessly work with WooCommerce product settings to override global defaults on a per-product basis.
  • Extendable: Expand the functionality by adding or modifying units and adjusting display settings using custom code snippets.

Configuring the Plugin

Installation

  1. Download the plugin ZIP file.
  2. Navigate to WordPress Admin > Plugins > Add New.
  3. Click Upload Plugin, choose the ZIP file, then click Install Now.
  4. Activate the plugin.

Setting Custom Units for a Product

Follow these steps to configure custom units for a WooCommerce product:

Step 1: Edit a Product

  1. Go to WooCommerce > Products.
  2. Click Add New or select an existing product to edit.
  3. Scroll down to the Product Data panel.

Step 2: Configure Custom Units

  1. Click the Shipping tab.
  2. Locate the Custom Units section.
  3. Select a Custom Weight Unit from the dropdown (e.g., grams, pounds, ounces).
  4. Select a Custom Dimension Unit from the dropdown (e.g., inches, centimeters, feet).
  5. Adjust the Decimal Precision if desired.

Step 3: Save and Preview

  1. Click Save Changes.
  2. Use the Admin Preview to view the custom units on the front end.
  3. Click Publish (or Update if editing an existing product).

Front-End Display

Once you configure the custom units, they display on the Single Product Page. In the Additional Information tab, the product’s weight and dimensions show up using your selected units and conversions.

Single Product Page

  • Your product details now reflect the custom weight and dimension units.

Available Filters

Developers can modify the plugin using various filters:

Weight Filters

  • cumfw_weight_units – Change the available weight units.
  • cumfw_convert_weight – Adjust the weight conversion logic.
  • cumfw_weight_decimals – Set the decimal precision for weight values.

Dimension Filters

  • cumfw_dimension_units – Modify the list of available dimension units.
  • cumfw_convert_dimension – Customize the dimension conversion logic.

Extending the Plugin with Custom Filters

Developers can extend this plugin by adding custom filters. For example, you can add new weight or dimension units, modify conversion rules, or adjust decimal precision.

Example: Adding a Custom Weight Unit

For instance, to add ounces (oz) as a weight unit, use the filter below. First, add your custom unit, then adjust conversion rates accordingly.

<?php

add_filter( 'cumfw_weight_units', function( $units ) {
    $units['ounce'] = __( 'Ounces (oz)', 'custom-unit-manager-for-woocommerce' );
    return $units;
});

// Define conversion logic for "ounce".
add_filter( 'cumfw_convert_weight', function( $weight, $weight_in_kg, $custom_weight_unit ) {
    if ( 'ounce' === $custom_weight_unit ) {
        // 1 kilogram = 35.274 ounces.
        return $weight_in_kg * 35.274;
    }
    return null;
}, 10, 3 );

Example: Adjusting Decimal Precision for Weight Units

Alternatively, remove decimals for grams by modifying the precision filter:

<?php

add_filter( 'cumfw_weight_decimals', function( $decimals, $unit ) {
    if ( 'g' === $unit ) {
        return 0; 
    }
    return $decimals;
}, 10, 2 );

Example: Adding a Custom Dimension Unit

Finally, to introduce a new dimension unit like yards (yd), implement this filter:

<?php

add_filter( 'cumfw_dimension_units', function( $units ) {
    $units['yard'] = __( 'Yards (yd)', 'custom-unit-manager-for-woocommerce' );
    return $units;
});

// Define conversion logic for "yard".
add_filter( 'cumfw_convert_dimension', function( $dimension, $dimension_in_meters, $custom_dimension_unit ) {
    if ( 'yard' === $custom_dimension_unit ) {
        // 1 meter = 1.09361 yards.
        return $dimension_in_meters * 1.09361;
    }
    return null;
}, 10, 3 );

Implementing Custom Code

You can insert these code snippets into your theme’s functions.php file or manage them with a plugin such as Code Snippets for better control.

Questions & Support

If you have any questions or need further assistance with woocommerce custom per product units, please Contact our Support. You may also visit the WooCommerce official website for additional resources.