Skip Navigation

[Resolved] Incorporating Relationship to Product order email notifications

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1282071

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.

#1282207

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?

#1288265

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

#1288751

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!

#1289027

ok, parent is "product", child is "speaker"

#1289043

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