Skip Navigation

[Resolved] Add information to email – continued

This support ticket is created 3 years, 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 27 replies, has 4 voices.

Last updated by Waqar 3 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1867573

MAI:

Hi Waqar,
on our page there is a possibility to buy a ticket for a sportscamp. We have a custom template to show all the info about the camp. Is it possible to take the data from the content template and pull it into the confirmation email that the customer gets, so they can see what they bought? Right now they only see the camp name and the price. Not the specific info with age, level, etc.
_________



WAQAR:
Hi,
I apologize for the delay in getting back on this as I had a busy queue after the weekend.
Just wanted to let you know that I'll be running some tests based on your requirement and will be able to share my findings with you, in next few hours.
Thank you for your patience.
regards,

Waqar
___________



WAQAR:
Hi,
Thank you for waiting.
I've performed some tests and research and I was able to include the content from a Toolset content template into the WooCommerce's "order completed" email, using the "woocommerce_email_before_order_table" hook from WooCommerce.
( ref: hidden link)
Example:
*custom code*

Note: You'll replace "123" with the post ID of the target "sportscamp" post and "456" with the ID of the target content template to use.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
Also, you'll find the information about the Toolset's "render_view_template" function here:
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template
I couldn't find any WooCommerce hook to send a duplicate email to another user, so it would best to consult their official support team or community forums, for that part.
regards,

Waqar
_________________



MAI:
Hi Waqar,
That sounds good. Just to be sure: When I put in an ID for the specific sportscamp - will that only include this single camp then? Because I need the data to appear on the mail no matter what camp the customer buys. Do you know what I mean?
_______________



WAQAR:
Hi,
Thanks for writing back.
Yes, in my example code snippet, I just used a fixed sports camp post ID, to give you an idea. To use the sports camp post ID dynamically, it would depend on what connection/relationship you have with the purchased/ordered product and the sports camp post.
Can you please share some information about that and if admin access would help in getting clearer picture, you're welcome to share that too.
Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.
regards,

Waqar
__________________



MAI:
*sharing admin details


________________



WAQAR:
Thank you for sharing the admin access.
I understand that the first form to add a new camp is on the page "Welcome host" ( /welcome-host/ ).
And the second form to add a new product is on page "Welcome host – product info" ( /welcome-host-product-info/ ).
Since a post-relationship exists between these two post types, I'll assume, that you'd also like to link the posts created as a result of these forms in this post-relationship's association.
Using some extra custom code, it may be possible to create a "Product" post, programmatically, when the first form for the camp is submitted, but, before I could suggest the next steps, I'll need to clearly understand the role/need of the fields used in the second form for the product.
The "Price" needs to be saved with the product post, but the title of the camp post can be the same as the product post.
Is there any special reason for the fields like "Antal ledige pladser på campen", "Indtast dit registreringsnummer", and "Indtast dit kontonummer" to be saved with the product post and not the camp post?
_______________



MAI: 

Hi Waqar,
I am so sorry for the late reply. I got hurt and had to have eye surgery so I was out for a few weeks.
You are right about all the things you write. The reason for the fields not being in the camp post is simply that it was not possible to create 1 post that contains all the information needed. Fields such as price, quantity (which is “Antal ledige pladser”) etc, that comes from the WooCommerce product was not possible to create in the same post form as the camp info. You guys helped me create the second post form so that we could get all the information we needed.
The reason that it was not possible was because we needed an actual product to appear in order to activate the purchase function on the site. And this was not possible with a normal post form as far as I remember.
Can you please let me know what you need to go to the next step from here? I am still just trying to get back to work, so please just fill me in.
My topic was closed so that is why I create the ticket like this.

#1867973

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mai,

Unfortunately this thread is a little difficult to follow.

Can you provide some information as to what is needed to be done so that I can have a look ?

Thanks,
Shane

#1868151

Hi Shane,

on our page there is a possibility to buy a ticket for a sportscamp. We have a custom template to show all the info about the camp. Is it possible to take the data from the content template (the customers camp of choice) and pull it into the confirmation email that the customer gets, so they can see what they bought? Right now they only see the camp name and the price. Not the specific info with age, level, etc.

#1868197

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mai,

The payment and email that is sent out with the confirmation of the order is usually done by Woocommerce.

I don't believe this is possible to do, however if it is it would be something that would require custom coding to achieve as you will need to modify the default Woocommerce confirmation mail.

This is actually out of our support forum scope.

Thanks,
Shane

#1870243

Hi Shane,

If you try and read the thread from the beginning you will see that Waqar was already working on it and we made it a lot of the way already. We just needed the final adjustments - can you maybe assign this task to him again?

#1870441

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mai,

I went ahead and re-assigned this ticket to Waqar

#1870457

hi Shane,

Thank you so much

#1871431

hi Waqar - did you see my messages here? Do i need to do anything?

#1872761

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Mai,

Sorry to hear about your injury and hope you're feeling better now.

We have a fairly busy queue at the moment, but I'll review all the information and will follow-up here, as soon as I can.

Thank you for your patience.

regards,
Waqar

#1872937

hi waqar,

Thank you, I am feeling better and better.

I understand - will this ticket stay open or do i have to do anything to keep it open?

Thanks

#1874771

Hi Waqar,
Just following up so the ticket won't close.

#1876063

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I apologize for the delay in getting back on this, as I had an unusually busy queue over the weekend.

I'll be able to share my findings in the next few hours. Thank you for your patience.

#1876865

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

price-generic-field.png

Thank you for waiting.

Reviewing the previous conversation and resuming where we left, the first step is to make the form "Create camp" automatically create a product post, with the same name as the newly created camp post and connect them in the "camp-product" relationship.

1. In your form "Create camp", please include a new numeric type generic field with the slug "product-price", as shown in the attached screenshot.

2. In your active child theme's "functions.php" file, you can include the following custom function linked to the "cred_save_data" hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data


add_action('cred_save_data', 'create_product_post_action',10,2);
function create_product_post_action($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==229)
	{
		$camp_title = get_the_title($post_id);

		$new_product = array(
			'post_title'    => wp_strip_all_tags( $camp_title ),
			'post_name'    => sanitize_title_with_dashes( $camp_title ),
			'post_type'    => 'product',
			'post_status'   => 'publish',
			'meta_input'   => array(
			'_price' => $_POST['product-price'],
			'_regular_price' => $_POST['product-price']
			)
		);

		// Create the Product post
		$product_id = wp_insert_post( $new_product );
		// if product post created, connect with the current camp post
		if(!is_wp_error($product_id)){
			toolset_connect_posts( 'camp-product', $post_id, $product_id );
		}
	}
}

As a result, when this "Create camp" form will be submitted, it will not only create a new "Camp" post but a "product" post with the same name will be created as well, with the price entered in the new generic field. Also, both these newly created "camp" and "product" posts will be connected in the relationship as well.

This means that you'll no longer need the second form "Create camp products".

Please let me know how it goes and once this bit is working we can move on to the next step.

#1882725

Hi Waqar,

It seems to be working! Wow it is amazing! We are ready for the next step

#1883415

Hello,

Waqar is on vacation.

Is this problem resolved? Feel free to create new ticket if you have other new questions.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.