• Resolved Steve D.

    (@sdowney2002)


    Hi Alex,

    I’m trying to concatenate two products fields and am having trouble calling them in a calculated field.

    I want to combine a custom ACF product field “internal_product_name” with the attribute “attribute_pa_medium”. (This is for product variations.)

    I have no trouble adding these fields individually to my export, but cannot figure out how to combine them. I’ve reviewed all your documentation without success.

    Thanks.

    Steve D.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi Steve

    You should use this way https://docs.algolplus.com/algol_order_export/add-calculated-field-for-product/

    Try code

    return $product->get_meta(“internal_product_name”). ” ” . $item->get_meta(“attribute_pa_medium”);

    but it might not work.

    thanks, Alex

    Thread Starter Steve D.

    (@sdowney2002)

    Hi Alex,

    Thanks for this! I’ll give it a try and let you know.

    Steve

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome.
    ok, ping me with results

    Thread Starter Steve D.

    (@sdowney2002)

    Alex,

    A TINY bit of progress!

    Using return $product->get_meta('internal_product_name') I can get the internal_product_name to display when the order line contains a SIMPLE product. However, when it’s a VARIABLE product, nothing displays.

    $item->get_meta('attribute_pa_medium') is still not working. However, if I replaceattribute_pa_mediumwithpa_medium (available from Product Order Items), I can get the attribute slug. I’ve tried various forms of “get attribute name from slug” without success.

    This screenshot of my AOE preview might help https://www.dropbox.com/s/vy7h0rw2ydji05l/downey-concatenating-problem.jpg

    And to confirm, this is the code I’m running:

    add_filter('woe_get_order_product_value_calculated_product_name', function ($value, $order, $item, $product, $item_meta) {
    return $product->get_meta('internal_product_name') .' ' . $item->get_meta('attribute_pa_medium');
    }, 10, 5);

    Steve

    • This reply was modified 2 years, 9 months ago by Steve D..
    Plugin Author algol.plus

    (@algolplus)

    Hi Steve

    You should find correct keys, so please, modify code to

    add_filter('woe_get_order_product_value_calculated_product_name', function ($value, $order, $item, $product, $item_meta) {
    echo "<pre>";
    print_r($product);
    print_r($item);
    die();
    return $product->get_meta('internal_product_name') .' ' . $item->get_meta('attribute_pa_medium');
    }, 10, 5);

    click Preview and check output.

    thanks, Alex

    Thread Starter Steve D.

    (@sdowney2002)

    Alex,

    My apologies! I didn’t get notification of your last post. I’m reading through the output now. Will keep you informed.

    Steve

    Plugin Author algol.plus

    (@algolplus)

    hi Steve

    please, use this code to get name by slug

    //replace slug with name
    $term = get_term_by( 'slug', $item['pa_medium'], 'pa_medium');
    if($term) $item['pa_medium'] = $term->name;

    If you fail to get necessary results – please, submit your settings as new ticket to https://algolplus.freshdesk.com/

    Use tab “Tools” to get them

    Thread Starter Steve D.

    (@sdowney2002)

    Alex,

    I think I’ve got it!

    To get the attribute label:
    $product->get_attribute( 'pa_medium' )

    To get the custom field: (since this is an ACF field, I must use ACF’s get_field)

    get_field('internal_product_name', $item['product_id'])

    Putting it all together:

    add_filter('woe_get_order_product_value_calculated_product_name', function ($value, $order, $item, $product, $item_meta) {
    
    if ($product->get_attribute ('pa_medium') ) {
    	$value = get_field('internal_product_name', $item['product_id']).' '.'-'.' '.$product->get_attribute( 'pa_medium' ) ;
    	
    }else {
    	$value = get_field('internal_product_name', $item['product_id']);
    }
    
    return $value;
    
    }, 10, 5);
    

    The if statement tests to see if the product has a attribute, and if so, adds a dash between the internal product name field and the attribute label.

    Thank you SO MUCH for your help! You got me looking in the right direction!

    Steve

    • This reply was modified 2 years, 9 months ago by Steve D..
    Plugin Author algol.plus

    (@algolplus)

    hi Steve

    Good news.

    You’re very welcome.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Concatenating Product Fields’ is closed to new replies.