Support

Account

Home Forums Backend Issues (wp-admin) How do I add WooCommerce Attributes?

Solving

How do I add WooCommerce Attributes?

  • I’m hoping this question can be answered simply by referring me to a support page that I haven’t been able to find yet. I am running a site with a WooCommerce shop. My client refuses, flat out refuses, to enter attributes for the products using the WooCommerce product editor interface – he will not click on the “Attributes” tab at all. So I need to use ACF to add a group of fields to the product editing page so that he can select attributes more easily/efficiently.

    I have googled like crazy but I can’t find a post that simply instructs me how to “Use ACF to add Attributes to WooCommerce Products. I’ve seen seems that seem to reference this ability, but I’m not finding the instructions I’m looking for.

    Is it possible? Am I making it more difficult than it actually is? Is there a support page that will spell it out for me? Thanks.

  • Hi @william-alexander

    Well first of your client is an idiot but fine! πŸ˜‰

    The attributes in WooCommerce is saved as an multidimensional array in the wp_postmeta table and looks like this:

    
    array (
      'testattribute' => 
      array (
        'name' => 'testattribute',
        'value' => 'attributevalue',
        'position' => '0',
        'is_visible' => 1,
        'is_variation' => 0,
        'is_taxonomy' => 0,
      ),
    )
    

    So you would have to try to replicate that using your own custom fields.
    I think it might be possible to do using nested repeater fields but you’ll not really end up with an easier way of input and the client wont be able to just hit “save attributes” but would have to update the whole product post each time they alter an attribute.

    Really you should tell your client you can attempt to do your own solution but will have to add x hours to the invoice (probably atleast 4-5h) and in the end the solution might not be easier than the default. There’s a reason why WooCommerce have it as it is and they have multiple devs working SOLELY on optimising every aspect of WooCommerce and millions of users liking it as it is.

    It all comes down to my first reaction, your client is an idiot πŸ˜‰

  • I wonder if this could be simplified somehow by the fact that much of the info in that array is going to be the same for every one of the attributes I’m trying to add. I’m really stuck with this – WooCommerce is well developed as a one-size-fits-all system, but the client wants the product entry streamlined for his very specific application, where products will have three and only three attributes. He enters many products and wants to eliminate any extra clicks. In the default new product process, adding attributes requires several clicks that seem unnecessary.

  • Hm okay.. I suppose you could hook into the save_post function yourself and add that general array yourself using update_post_meta.

    That way your client could create the product as he wishes and ignore attributes. Then save the product. Then go into the attributes and alter it if he needs to (or just let them be if he needs the default).

  • william.alexander, did you manage to get this to work on the front-end? if so, could you walk me through your process?

    I’m having similiar issue where I managed to create a backend custom field so it shows right after the Product Title. But getting it to show on the front-end is a mystery to me.

  • No, I was never able to get this to work. It appears that this is not functionality that is available with ACF.

  • @prima

    In what way do you mean to get it working on the front end?
    The original question is about adding WooCommerce product attributes through ACF fields when creating a produkt.

  • I have done this very thing for a client (but for different reasons)…

    Here’s the code I used to display a WYSIWYG custom field in the attributes list:

    add_filter( 'woocommerce_get_product_attributes', 'ariel_display_recordings_attribute', 20 );
    function ariel_display_recordings_attribute( $attributes ) {
    	$ariel_recording_details = get_field('ariel_recording_details');
    	if (!empty(get_field('ariel_recording_details'))) {
    
    	$attribute = array(
    		'name'         => 'Recording',
    		'value'        => $ariel_recording_details,
    		'is_visible'   => '1',
    		'is_taxonomy'  => '0',
    		'is_variation' => '0',
    		'position'     => '0',
    	);
    
    	$attributes['ariel_recording_details'] = $attribute;
    	}
    
    	return $attributes;
    }

    You can also add additional code to attributes.php to specify what order you’d like attributes to appear in…

  • Hmm, it seems that this doesn’t work properly with Woocommerce 3.0.x – the fields still show on the front-end, but the admin GUI is all messed up! πŸ™

  • Does anyone know why this would no longer work in Woocommerce 3.0.x?

    All tabs in wp-admin no longer show & ‘visual’ tab for text editor no longer works! Does anyone from support ever read these forums?

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.