How to create a global product attribute and its translations programmatically with WooCommerce+WPML

49 Views Asked by At

I create my product attributes as follows

        $args = array(
            'slug' => $a_slug,
            'name' => $a_name,
            'type' => 'select',
            'orderby' => 'menu_order',
            'has_archives'  => false,
        );

        // Enregistrer l'attribut global s'il n'existe pas
        $attributeId = wc_create_attribute( $args );
        
        $new_attr = wc_get_attribute($attributeId);
        
        $a_taxonomy = $new_attr->slug;
        
        register_taxonomy( $a_taxonomy, array( 'product' ), array() ); 

For this global attribute, I can also create the terms, as well as their translations

What I can't seem to do is define the translations of this global attribute. While it can be done via the backend by going to the menu WooCommerce > WooCommerce Multilingual & Multicurrency > Attributes > (Select an attribute) > Translations of taxonomy Size labels and slug

I would simply like to create the global "Size" attribute in the primary language which would be English. And then define that the French translation of this attribute name is “Taille”

Regards

0

There are 0 best solutions below