• can you please let me know how I can add Custom Product Attribute and Variable in WooCommerce Programatically? I know this easy to be done in Woocommerce GUI but I need to do this through functions.php

    I have a Attribute Called “Class” and Some Variables as [A,B,C,D] now I would like to add them to the Cart and Shop page, I already tried this function but it didn’t add any thing to the page:

    function woocommerce_variable_add_to_cart() {
       //Type attribute
        $product_attributes['type'] = array(
            //Make sure the 'name' is same as you have the attribute
            'name' => htmlspecialchars(stripslashes('Class')),
            'value' => $attributes,
            'position' => 1,
            'is_visible' => 1,
            'is_variation' => 1,
            'is_taxonomy' => 0
        );
    
    //Add as post meta
    update_post_meta($post_id, '_product_attributes', $product_attributes);
    
    }

    Thanks

  • The topic ‘Adding Custom Product Attribute and Variable in WooCommerce Programatically’ is closed to new replies.