• Hi! I’ve been using DataFeedr for several years. Suddenly on Product Set updates, new attribute terms are being created in WooCommerce products. For example: the WooCommerce attribute I created, Antenna Amplified (slug: p-antenna-amplified) with two terms Y (slug: p-antenna-amplified-yes) and N (slug: p-antenna-amplified-no) are being changed to “p-antenna-amplified-yes-2” “p-antenna-amplified-yes-2-2” and “p-antenna-amplified-no-2” “p-antenna-amplified-no-2-2”, etc. on each Product Set update.

    P.S. I’m using a Custom Script, per your online code, to prevent product titles, descriptions & excerpts from being overwritten during Product Set updates. The custom plugin continues to work fine. Any ideas on why the attribute terms are changing? Thanks! Chuck Stratton

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author datafeedr

    (@datafeedrcom)

    Hi Chuck

    If you are using Custom Attributes you also need to add this code to prevent custom attributes from being overwritten during a Product Set update:

    https://datafeedrapi.helpscoutdocs.com/article/44-prevent-attributes-from-being-overwritten-during-product-set-updates

    Hope this helps!

    Eric

    Thread Starter Chuck

    (@chuckstr)

    Thanks! I have a variety of products with over 40 different attributes and 5x that many terms. Any way to simplify the code you provided. I’m not using any imported DataFeedr attributes. They are all custom attributes.

    Thread Starter Chuck

    (@chuckstr)

    The attributes will change from time to time and I’m trying to avoid replacing/updating the plugin list of attributes. Thanks.

    Plugin Author datafeedr

    (@datafeedrcom)

    Hi Chuck

    You don’t need to add the terms to the custom code but you will need to add your various attribute slugs to the $attrs array.

    So you might have:

    $attrs = [
        'color',
        'size',
        'gender',
        'material',
        'condition',
    ];

    You can find all of those 40 slugs here WordPress Admin Area > Products > Attributes.

    Hope this helps!

    Eric

    Plugin Author datafeedr

    (@datafeedrcom)

    So you aren’t using any Global Attributes? You are only using Custom Attributes?

    Is that correct?

    Thread Starter Chuck

    (@chuckstr)

    What’s interesting, I’ve never had this problem before. What has changed, or what may I have done to now have to do this? Is there a way to not import “any” attributes?

    Thread Starter Chuck

    (@chuckstr)

    Sorry, our messages are overlapping. No, I am not using any Global Attributes.

    Plugin Author datafeedr

    (@datafeedrcom)

    Hi Chuck

    I am confused… You mention that you are “not using any Global Attributes” but you said “the WooCommerce attribute I created, Antenna Amplified … with two terms …”.

    Where did you create the WooCommerce Attribute “Antenna Amplified”? On this page: WordPress Admin Area > Products > Attributes?

    Thanks
    Eric

    Thread Starter Chuck

    (@chuckstr)

    To clarify, I’m not using any DataFeedr imported attributes. All attributes are custom on my end. Thanks.

    Plugin Author datafeedr

    (@datafeedrcom)

    OK, I see. Thanks for clarifying.

    And just so I fully understand…

    Were all of your attributes created here: WordPress Admin Area > Products > Attributes?

    Thread Starter Chuck

    (@chuckstr)

    Yes.

    Also, I’m not seeing anywhere to set DataFeedr Global attributes, even if I wanted to.

    Plugin Author datafeedr

    (@datafeedrcom)

    Correct, there is no place to create Datafeedr Global Attributes… Datafeedr relies on the WooCommerce attribute system.

    Can you try adding the following code to your custom plugin:

    
    add_filter( 'dfrpswc_filter_attribute_value', function ( $value, $attribute, $post, $product, $set, $action ) {
    
    	$attrs = array_column( wc_get_attribute_taxonomies(), 'attribute_name' );
    
    	if ( 'insert' === $action ) {
    		return $value;
    	}
    
    	foreach ( $attrs as $attr ) {
    
    		$name = dfrapi_string_starts_with( $attr, 'pa_' ) ? $attr : 'pa_' . $attr;
    
    		if ( $name !== $attribute ) {
    			continue;
    		}
    
    		$value = wc_get_product_terms( $post['ID'], $name, [ 'fields' => 'names' ] );
    		$value = implode( WC_DELIMITER, $value );
    	}
    
    	return $value;
    
    }, 10, 6 );
    
    

    That code will recognize your existing and future attributes so you won’t need to update the code if you add or remove WooCommerce Global attributes in the future.

    Hope this helps!

    If you have any other questions, please don’t hesitate to ask.

    Thanks,
    Eric

    • This reply was modified 2 years, 6 months ago by datafeedr.
    • This reply was modified 2 years, 6 months ago by datafeedr.
    Thread Starter Chuck

    (@chuckstr)

    Great! Added in the code. What do I do with this code that is already in the default code from the internet?

    /**
    	 * Add slug value for each attribute that should not be modified during a Product Set update.
    	 * Slugs can be found here: WordPress Admin Area > Products > Attributes
    	 */
    	$attrs = array(
    		'color',
    		'size',
    	);
    
    	if ( 'insert' == $action ) {
    		return $value;
    	}
    
    	foreach ( $attrs as $attr ) {
    
    		$name = ( substr( $attr, 0, 3 ) === 'pa_' ) ? $attr : 'pa_' . $attr;
    
    		if ( $name == $attribute ) {
    			$value = wc_get_product_terms( $post['ID'], $name, array( 'fields' => 'names' ) );
    			$value = implode( WC_DELIMITER, $value );
    		}
    	}
    
    	return $value;
    }
    Plugin Author datafeedr

    (@datafeedrcom)

    The code I provided above is a replacement for all of the code you mentioned here.

    Does that make sense?

    Thread Starter Chuck

    (@chuckstr)

    Yep. Got it. I’ll mark out the old code and add the new code you provided today. I’ll then do a test on a single Product Set update and see what happens.

    You are awesome! Thank you very much for your help.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Product Set updates replacing attribute terms’ is closed to new replies.