Website Building » WooCommerce » How Do I Set Global Attributes in WooCommerce?

How Do I Set Global Attributes in WooCommerce?

Last updated on January 17, 2023 @ 5:34 am

If you want to set global attributes in WooCommerce, there are two ways to do it. You can either use the built-in WooCommerce interface or add the code to your functions.php file.

To set global attributes in WooCommerce:

    1. Go to WooCommerce > Settings > Products > Attributes.

    2. Select global from the dropdown next to Configure.

    3. Enter the Name, Slug, and Type.

    4. Select the Used for variations checkbox if you want to use this attribute for variations.

    5. Click the Add attribute button.

    6. Repeat these steps for each global attribute you want to add.

    7. Click the Save changes button at the bottom of the page to save your changes.

Adding global attributes via code:
If you want to add global attributes via code, you can do so by adding the following code to your functions.php file:

<?php 

    function my_attribute(){

        $args = array(

            'id'                => 0, // id should be unique - required

            'name'              => 'my_attribute', // name should be sanitized - required

            'slug'              => 'my_attribute', // slug should be sanitized - required

            'type'              => 'select', // type - required

            'order_by'          => 'menu_order', // order_by - default is menu_order

            'has_archives'      => false, // has_archives - default is false

            );

        register_taxonomy( $args['name'], array( 'product' ), $args ); 

    }

    add_action('init','my_attribute');  ?>
Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.