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().'/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.