Skip Navigation

[Resolved] Add information to email – continued

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.

Tagged: 

This topic contains 27 replies, has 4 voices.

Last updated by Waqar 6 months, 3 weeks ago.

Assigned support staff: Waqar.

Author
Posts
#1884137

Hi Lou,

No Waqar and I are not finished yet. When will he be back? 🙂

Thanks for letting me know.

#1884687

Waqar
Supporter

Languages: English (English )

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

Hi Mai,

I'm back from vacation and glad that it is working.

I'll share the information about the next step of getting the related camp's details in the order completion email, today.

regards,
Waqar

#1885059

Hi waqar,

Thanks, I hope you had a good vacation.

Sounds great, I though I should share that the quantity function (number of available spots on the camp) is also very relevant. So the host also needs to type in the number of available spots on the camp and then when they are sold out, the product part of the camp should change from "in stock" to "backorder". So you'll be on some sort of waiting list. Ish.

#1885927

Waqar
Supporter

Languages: English (English )

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

Thank you for waiting.

To link the form's generic field "pladser" with the available stock quantity of the created product, you can update the "$new_product" array from my code snippet ( ref: https://toolset.com/forums/topic/add-information-to-email-continued/#post-1876865 ), to also include custom fields "_manage_stock" and "_stock":


		$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'],
			'_manage_stock' => 'yes',
			'_stock' => $_POST['pladser']
			)
		);

The updated code snippet that I shared earlier ( ref: https://toolset.com/forums/topic/getting-content-template-data-in-woocommerce-email/#post-1828465 ) for the WooCommerce's order completed email, will look like this:


add_action( 'woocommerce_email_before_order_table', 'custom_add_content_specific_email', 20, 4 );
function custom_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
	if ( $email->id == 'customer_completed_order' ) {
		// ID of the CT to get the content from
		$target_ct = 12345;
		ob_start();
		// cycle through each product in the order
		foreach ($order->get_items() as $item_id => $item_values) {
			// get the product's ID
			$product_id = $item_values['product_id'];
			// get the related camp's ID
			$related_camp_id = toolset_get_related_post( $product_id, 'camp-product' );
			// get the content template's output with the related camp post set as the source
			echo render_view_template( $target_ct, $related_camp_id );
		}
		echo ob_get_clean();
	}
}

Please replace "12345" with the actual content template's ID, to get the related camp's details.

Important Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#1888543

hi Waqar,

Sorry for the late reply, I had some days off.

Thanks for all this - i will try it out!

So when you say "Please replace "12345" with the actual content template's ID, to get the related camp's details." - does that then get the camp info no matter what camp is chosen or is it only working if 1 specific camp is chosen? '

Thanks.

#1888567

Waqar
Supporter

Languages: English (English )

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

You're very welcome.

> So when you say "Please replace "12345" with the actual content template's ID, to get the related camp's details." - does that then get the camp info no matter what camp is chosen or is it only working if 1 specific camp is chosen? '

- The ID "12345" in this context refers to the target content template to get the data from and not the camp that should be used as a source.

The code snippet from my last message will:

1. Get the ID of the product ordered
2. Get the related camp's ID, from the product ID acquired in step 1.
3. Set the camp ID from step 2 as a source for the content template "12345" (or any provided content template ID).

Suppose that you have a product named "A test Product" which has the related camp post of the same name.

When someone will complete the order for that product, the information from the camp "A test Product" will be fetched and will be shown using the content template "12345".

#1889355

Hi Waqar,

To link the form's generic field "pladser" with the available stock quantity of the created product, you can update the "$new_product" array from my code snippet ( ref: https://toolset.com/forums/topic/add-information-to-email-continued/#post-1876865 ), to also include custom fields "_manage_stock" and "_stock":

$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'],
'_manage_stock' => 'yes',
'_stock' => $_POST['pladser']
)
);

____

I tried to add this but i do not see the number of spots available on the template like i see the price. I thing i am doing something wrong.

I did not try the email thing yet, i just wanted to do one thing at a time.

#1890423

Waqar
Supporter

Languages: English (English )

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

Thanks for the update.

I tested the form at /welcome-host/ and it created a product and a camp post named "Test entry from Waqar with 25 openings", successfully.

- The created camp and the product are connected in a relationship
- The price of the product is set to 100, as entered in the form
- The stock quantity of the product is set to 25, as entered in the form

This confirms, that the custom function linked to form submission is working as expected.

To show the product's stock or the number of places available in camp, you can use "wpv-post-field" shortcode in a view that shows the related products:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field )


[wpv-post-field name='_stock']

#1893987
Skærmbillede 2021-01-04 kl. 15.59.22.png
Skærmbillede 2021-01-04 kl. 15.59.04.png

hi Waqar,

I tried putting in the shortcode but it is not working. It is put in under "Antal ledige pladser" - i was wondering if it can just show the current stock mode - so if it start at 25, it says 25. When 1 is sold it says 24 etc.

Also i noticed that the dynamic sources:
"Alder & Niveau"
is not displaying the source. I added a screenshot of what data needs to be displayed in the field.

#1895843

Waqar
Supporter

Languages: English (English )

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

The stock custom field is saved with the product post and not with the camp post. And your screenshot shows the field's shortcode being used on the single camp post.

In this case, you'll need to include the item attribute to get the field data from the related product post:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/ )


[wpv-post-field name='_stock' item='@camp-product.child']

And yes, since we're using WooCommerce's "_stock" custom field, it will automatically be updated with orders, by WooCommerce.

As for the single field block for "Alder & Niveau", it was set to use custom fields as the source, whereas this is a custom taxonomy. I've updated the source to the correct taxonomy and it is working now.
( screenshot: hidden link )

Note: this thread has already become very long, so it would be better to start new tickets for any new questions or concerns.

#1899443

Hi Waqar,

Wow now it works! That's great, thank you! And all these data will be pulled into the emails for the customer and the host when a purchase is made?

#1899497

Hi Waqar and Christian,

I tried creating a new ticket but i can only choose to "Start a chat", "Suggest an improvement" or "Need help with my account" - usually i can create a new ticket like this one.

Anyway - Christian helped me creating an option for the host to edit a camp in the frontend after it has been created. Let's say the host typed in a wrong address or wants to add another coach - this is now possible and it is super great. Right now there are 2 edit buttons: 1 for the post form with camp info and 1 for the product info.

In the meantime Waqar managed to actually convert the 2 post forms into 1 post form. So now you type in price, number of available sports and all the relevant data from the product form, in the info form. So now we only have 1 form. This is amazing.

I was now testing and it is not possible to edit the price or number of available spots on the frontend yet. You can see the fields in the form but it says that there is an error with this field and you can not edit anything. My question is, if it is possible to include those fields and make it possible to edit the price and number of available spots in the same form so that we also only have 1 form to edit in the frontend instead of 2?

Thank you.

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-edit-related-product-field-through-the-edit-form-continued/

#1901169

Waqar
Supporter

Languages: English (English )

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

Thanks for the update and glad you've been making progress.

When a chat supporter is available, every new ticket is started as a chat and if not, it is moved to a regular email support ticket.

I've split the question about the edit form into a new ticket and will reply to it separately.
( ref: https://toolset.com/forums/topic/split-edit-related-product-field-through-the-edit-form-continued/ )

You're welcome to mark this ticket as resolved.