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
Hi Alex,
Thanks for this! I’ll give it a try and let you know.
Steve
you’re welcome.
ok, ping me with results
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 4 years, 3 months ago by
Steve D..
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
Alex,
My apologies! I didn’t get notification of your last post. I’m reading through the output now. Will keep you informed.
Steve
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
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 4 years, 2 months ago by
Steve D..