Skip to main content
Login Join
Snippet · PHP

Add a New Attribute Type to the WooCommerce Attribute Selector

Shared by Mehraz Morshed · September 2, 2026 · @woocommerce_product_option_terms, product_attributes_type_selector

11 views
Back to Snippets

Add a new attribute type to the WooCommerce attribute selector. This is the foundation for creating custom swatch types.

Note: After adding this, you also need to handle the attribute selection form in the product editor using the woocommerce_product_option_terms​ hook.

add_filter( 'product_attributes_type_selector', 'swatches_add_attribute_type' );

function swatches_add_attribute_type( $types ) {
    $types['color'] = 'Color';
    return $types;
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments