Skip Navigation

[Resolved] Follow up on ticket regarding list for the host

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.

Our next available supporter will start replying to tickets in about 5.18 hours from now. Thank you for your understanding.

This topic contains 34 replies, has 2 voices.

Last updated by Waqar 5 months, 1 week ago.

Assigned support staff: Waqar.

Author
Posts
#2011553

Waqar
Supporter

Languages: English (English )

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

Hi Mai,

Thank you for waiting and I just wanted to let you know that I'm still working on it.

No further action is needed from your side at the moment and I'll update you as soon as this testing completes.

regards,
Waqar

#2011733

Thank you so much Waqar

#2017595

Hi Waqar,
I am sorry but my boss is very pushy about the list function and the email function - do you have any idea how long it will take until the tests are over? Can i tell him anything?

Thanks 🙂

#2017943

Waqar
Supporter

Languages: English (English )

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

Hi Mai,

I'm sorry to keep you waiting, but I'll be able to share some notes by the end of the day today.

regards,
Waqar

#2019085

Thank you Waqar, I will wait for you

#2020255

Waqar
Supporter

Languages: English (English )

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

Hi Mai,

I've been investigating why the custom code for adding additional content in the WooCommerce emails is not working as it was before and discovered something alarming.

All the custom code, that you've added as a result of support tickets between us in the last months, is no longer available on the website. I've checked the Toolset's custom code section and the "functions.php" files in the "The7" theme and the "The7 Child Theme".

The missing code includes the snippets for not only WooCommerce emails but also the custom functions to automatically create and update connected product posts when a camp post is created or updated.

While I'm trying to recover that code from the previous support tickets and older duplicator backups from your website, it is very important that we narrow down to what caused this in the first place, so it can be avoided in the future.

1. Did someone other than you worked on the website, recently?

2. Were the files in the "The7" theme and/or "The7 Child Theme" were updated/replaced?

3. Was the website restored to a backup from an earlier date?

4. Did you or someone else moved the custom code to a different theme or plugin?

Please let me know the answers about these and I'll keep you updated on the recovery of the missing code.

regards,
Waqar

#2020273

Waqar
Supporter

Languages: English (English )

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

I have some good news.

From an old duplicator package, I was able to recover the missing custom code from the functions.php file in "The7 Child Theme", which looks like it is all of it.


<?php
//* Code goes here

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

function enqueue_parent_styles() {
   wp_enqueue_style( 'parent-style', get_template_directory_uri().'https://cdn.toolset.com/style.css' );
}

/**
 * Auto-login new CRED user
 */
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){

	if ( 227 == $form_data['id'] ) { // Edit as required

		if ( !empty( $_POST['user_login'] ) && !empty( $_POST['user_pass'] ) ) {

			// get the user credentials from the $_POST object
			$user = array(
				'user_login'	=>	$_POST['user_login'],
				'user_password'	=>	$_POST['user_pass'],
				'remember'		=>	true
			);
			$login = wp_signon( $user, false );

			if ( is_wp_error($login) ) {
				error_log( $login->get_error_message() );
			}

		}
	}
}

add_action('after_setup_theme', 'remove_admin_bar');
 function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

add_filter( 'woocommerce_return_to_shop_redirect', 'st_woocommerce_shop_url' );
/**
 * Redirect WooCommerce Shop URL
 */

function st_woocommerce_shop_url(){

return site_url() . '/';

}

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

add_action( 'woocommerce_email_after_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_on_hold_order') || ($email->id == 'new_order') ) {
        // ID of the CT to get the content from
        $target_ct = 1288;
        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();
    }
}

add_action('cred_save_data', 'edit_product_post_action',10,2);
function edit_product_post_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==1005)
    {
        // update the stock field from pladser field value
        update_post_meta( $post_id, '_stock', $_POST['pladser'] );
    }
}

I'll recommend adding the above code in the functions.php file in the "The7 Child Theme" and make sure, that:

1. The "The7 Child Theme" is always active on the website, not the parent theme "The7".

2. Whenever you need to update the theme, only the parent theme "The7" should be updated and not the child theme "The7 Child Theme".

After the code has been added back, please perform some tests by adding a camp post through the create a camp form and see if the associated product is also created automatically.

Next, also place a test order for that product to confirm if the extra information about the camp is included in the WooCommerce email.

Note: Once you'll confirm that everything is working as it was before, I'll move to the last remaining item of including the camp's host in the WooCommerce order email.

#2020699

Hi Waqar,

Oh my gosh! I have no idea how this happened. I mean, I did not edit the functions.php but i did confirm that it was empty (0kb)!!!! I don't think anyone else have access except you guys! I am so sorry, i do not know how this happned.

But i do confirm that the code is back in the funcitons.php, the price and product works, i went through checkout and the info is back on the email.

Thank you so much!

#2024207

Waqar
Supporter

Languages: English (English )

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

Thanks for the update and glad that everything is working again now.

I managed to extend the recipient list for the new order email so that it is also sent to the related camp's host email:
( host email will be used from the "kontaktperson-1-email" field added in the camp post )


add_filter( 'woocommerce_email_headers', 'extend_order_placed_email_to_camp_host', 9999, 3 );
 
function extend_order_placed_email_to_camp_host( $headers, $email_id, $order ) {
    // if specific email type
    if ( 'customer_on_hold_order' == $email_id ) {
      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 related camp's host name from "kontaktperson-1-navn" field
            $camp_host_name = types_render_field( "kontaktperson-1-navn", array( "item" => $related_camp_id ) );
            // get the related camp's host email from "kontaktperson-1-email" field
            $camp_host_email = types_render_field( "kontaktperson-1-email", array( "item" => $related_camp_id, "output" => 'raw' ) );
            // add host name and email as CC
            $headers .= "CC: ".$camp_host_name." <".$camp_host_email.">" . "\r\n"; // del if not needed
      }
    }
    return $headers;
}

You can add this code snippet at the bottom of the child theme's "functions.php" file. As the camp host will now receive an email for every order placed for his/her camp's product, it will be easier for him/her to keep track of the bookings.

#2025759

Hi Waqar,

I put the code into the functions.php file. We moved the site to the real domain as we need to launch asap. The new domain is hidden link but the wp-login is the same as before 🙂

So i tried it out and it seems like it is working for me but my boss can not get it to work. I made sure he was the host on the camp he tried to buy. But he only recieve the email as a customer not a host. He tried these camps:

hidden link
hidden link
hidden link
hidden link

I don't know why the emails does not go through to him?

#2025771

Waqar
Supporter

Languages: English (English )

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

As it worked for me and you, it's most likely related to the email address being used for the testing.

I would check and confirm the email address used in the "kontaktperson-1-email" field of the camps being used for the testing, and that the host email and the customer who is placing the order are different.

Please also suggest checking the spam folder and testing with a different email address or user.

#2025941

Hi Waqar,

His mail is a G-mail so it would be a bit unfortunate if it did not work. He checked spam and nothing there.
I have tried similar problems before with wordpress - is there some way to "force" the mails through?

I will test again for myself with 2 different addresses

#2025943
Skærmbillede 2021-04-19 kl. 10.42.42.png

Hi Waqar,

Now I tried with one of my other mail and I can confirm that the mail I receive is because I am the admin of the site - my mail is attached as admin mail for WP and Woocommerce.

The CC mail in the mail is the host mail and nothing is received there.
See screenshot.

#2025957
Skærmbillede 2021-04-19 kl. 10.42.42.png

Hi Waqar,

I don't see the message I just sent so I will send it again .

I just tested with another email address and I can confirm that the host mail is not getting an email at my end. It was the admin mail because my mail is the admin on WP and Woocommerce on the site - so it is the "normal" mail I receive - I do not receive the mail as a host.

The screenshot is from the customer mail and the host is CC but the host are not receiving anything.

#2026145

Waqar
Supporter

Languages: English (English )

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

I think there is some security restriction in place on the live website's server, which is blocking me.

The fact that your screenshot shows "To" and "CC" email addresses separately, confirms that the custom code is working as expected.

If you'll remove the last code snippet, you'll see only "To" email address will get this "Din FindSportsCamps ordre er blevet modtaget!" email. Also, it is important to remember that this email by default is sent only to customer who places the order and not the website's admins.
( the website's admin receive a different email with subject "[FindSportsCamps]: Ny ordre #12345" )

There is a simple test for this. You can add a new camp and product and set the email in "kontaktperson-1-email" field in camp to any distinct email address that you haven't used on the website.

Next, place a new order for this product using any customer account which is not added as an admin on the website. Please check on which email addresses you receive the "Din FindSportsCamps ordre er blevet modtaget!" email.