Tell us what you are trying to do?
I have a woocommerce event site with a number of speakers, and products set up with relationships to the speakers (via toolset). I really need the order receipts (both to the customer and to the admin) to reflect the related speaker name in addition to the product title, (e.g. the line item in the receipt would say 'Workshop title' by 'related speaker name'). How can I do this? Thanks, in advance, for your help.
Hi, I assume you're talking about the emails sent out by WooCommerce, correct? Customizing those email templates requires some level of PHP experience, because Toolset doesn't provide a way to edit those in wp-admin. Here's a visual reference showing some different areas you can modify, along with the hook names:
https://businessbloomer.com/woocommerce-visual-hook-guide-emails/
I think woocommerce_order_item_meta_start is the hook you would use to add text after the Product title. I found a simple example here: https://www.tychesoftwares.com/how-to-customize-woocommerce-order-emails/
Since that's not really Toolset-related, setting up that part of the code is outside the scope of Toolset support. Within that code, though, I can show you how to use PHP to display information from related posts using our Post Relationships API. I need to know:
- What type of relationship is set up - one to many or many to many?
- What is the relationship slug?
- What are the slugs of the two post types?
- Which is the parent and which is the child?
Oops! I missed your reply - sorry for the delay. Okay, that help would be GREAT! Here are the answers you asked for:
- many to many relationship
- slug = product-speaker
- post type slugs: speaker, product
- I don't think either is a parent, but Product is listed first, on the left side, so maybe that one?
Let me know if you need any additional info!
Sara
Even many-to-many relationships are defined by a parent and a child post type. To find out which is which, go to Toolset > Relationships and edit the relationship. Click the checkbox that says "I understand that changes to these settings may delete post associations in this Relationship" and then Edit Settings. Don't make any changes, just note which is the parent and which is the child. Let me know and we can go from there. Thanks!
ok, parent is "product", child is "speaker"
Okay here's how you would get all the Speakers related to as specific Product and output their titles separated by " and ":
$speakers = toolset_get_related_posts(
$item_id,
'product-speaker',
array(
'query_by_role' => 'parent',
'limit' => 1000000,
'offset' => 0,
'args' => array(),
'return' => 'post_id',
'role_to_return' => 'child'
)
);
$output = '';
$separator = '';
foreach($speakers as $speaker) {
$output .= $separator;
$output .= get_the_title($speaker);
$separator = ' and ';
}
echo $output;
The variable $item_id is provided for you in the woocommerce_order_item_meta_start hook. Here's the documentation for the Post Relationship API: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts