array(
'name' => __('Testimonials'),
'singular_name' => __('Testimonial')
),
'rewrite' => array(
'slug' => 'testimonial',
'with_front' => false,
),
'public' => true,
'has_archive' => false,
'supports' => array('title', 'thumbnail'),
'menu_icon' => 'dashicons-testimonial',
)
);
}
add_action('init', 'create_testimonials_cpt');
function testimonial_carousel_shortcode($atts) {
ob_start();
?>
';
while ($query->have_posts()) {
$query->the_post();
$our_product_trainings_logo = get_field( "our_product_trainings_logo" );
$our_product_trainings_time_icon = get_field( "our_product_trainings_time_icon" );
$our_product_trainings_time = get_field( "our_product_trainings_time" );
$our_product_trainings_level_icon = get_field( "our_product_trainings_level_icon" );
$our_product_trainings_level = get_field( "our_product_trainings_level" );
?>
';
wp_reset_postdata();
} else {
echo '
No trainings found.
';
}
return ob_get_clean();
}
add_shortcode('product_trainings', 'display_product_trainings_shortcode');
function custom_product_shortcode($atts) {
$current_training_id = get_the_ID();
if ( function_exists('pll_current_language') ) {
$current_lang = pll_current_language();
}else{
$current_lang = 'en';
}
ob_start();
$today = current_time('Ymd'); // respektiert WP-Zeitzone
if ( is_tax('training_category') ) {
$current_training_id = get_queried_object_id();
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'training_category',
'value' => $current_training_id,
'compare' => 'LIKE'
),
array(
'key' => 'product_date',
'value' => $today,
'compare' => '>',
'type' => 'NUMERIC'
),
),
'meta_key' => 'product_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
}else{
if( $current_training_id != '51909'){
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'training_course',
'value' => $current_training_id,
'compare' => '=',
),
array(
'key' => 'product_date',
'value' => $today,
'compare' => '>', // strikt in der Zukunft
'type' => 'NUMERIC' // wichtig für YYYYMMDD
),
),
'meta_key' => 'product_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
}else{
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'product_date',
'value' => $today,
'compare' => '>', // strikt in der Zukunft
'type' => 'NUMERIC' // wichtig für YYYYMMDD
),
),
'meta_key' => 'product_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
}
}
$loop = new WP_Query($args);
$html = '';
if ($loop->have_posts()) {
$html .= '
';
while ($loop->have_posts()) {
$loop->the_post();
$product_date_raw = get_field('product_date');
$guaranteed_to_run = get_field('guaranteed_to_run');
$days = get_field('days');
$language_name = get_field('language_name');
$method = get_field('method');
$our_trainer = get_field('our_trainer');
$product_details_schedule = get_field('product_details_schedule');
$product_details_location = get_field('product_details_location');
$product_details_certificate_image = get_field('product_details_certificate_image');
$schedule_title = get_field('product_details_schedule_title');
$location_title = get_field('product_details_location_title');
$certificate_title = get_field('product_details_certificate_title');
$availability_status = get_field('availability_status') ?: 'Seats Available';
$product = wc_get_product(get_the_ID());
$price = $product ? $product->get_price_html() : '';
$product_url = get_permalink();
$html .= '
';
$html .= '
';
$day = date('d', strtotime($product_date_raw));
$month_year = date('M. Y', strtotime($product_date_raw));
if ($product_date_raw && $days) {
$start_date = DateTime::createFromFormat('d/m/Y', $product_date_raw);
$end_date = clone $start_date;
$end_date->modify('+' . ($days - 1) . ' days');
$html .= '
';
$html .= '
' . $start_date->format('d M.') . ' ' . $start_date->format('Y') . ' - ' .
$end_date->format('d M.') . ' ' . $end_date->format('Y') . '
';
//$html .= '
' . esc_html($month_year) . '
';
if ($guaranteed_to_run) {
$html .= ' ' . ( $current_lang == 'de' ? '(Durchführungsgarantie)' : '(Guaranteed to run)' );
}
$html .= '
';
}
/*$html .= '
';
$html .= '
' . esc_html($day) . '
';
$html .= '
' . esc_html($month_year) . '
';
$html .= '
';*/
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
// Trainer Section
$output = '
';
$output .= '
';
foreach($our_trainer as $tr) {
$output .= '
';
$output .= '
' . get_the_post_thumbnail($tr->ID, 'full') . ' ';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= "
";
$output .= "
";
$output .= get_the_post_thumbnail($tr->ID, 'full');
$output .= "
";
$output .= "
";
$output .= "
" . $tr->post_title . " ";
$output .= "
";
$output .= apply_filters('the_content', $tr->post_content);
$output .= "
";
$output .= '
';
$trainer_heading = get_field('heading', $tr->ID);
if (!empty($trainer_heading)) {
$output .= '
' . esc_html($trainer_heading) . ' ';
}
$output .= "
LinkedIN ";
$output .= "
";
$output .= '
';
$output .= '
';
$output .= '
';
}
$output .= '
';
$output .= '
' . ($current_lang == 'de' ? 'Deine Trainer' : 'Your trainers' ) . ' ';
$output .= '
';
$html .= $output;
// Price
$html .= '
';
$html .= '
' . $price . ' ';
$html .= '
';
$html .= '
';
// Book Now with Quantity
$html .= '
';
$html .= '
';
if (
(!empty($product_details_schedule)) ||
(!empty($product_details_location) && is_array($product_details_location)) ||
(!empty($product_details_certificate_image) && is_array($product_details_certificate_image))
) {
$html .= '
';
if (!empty($product_details_schedule)) {
$html .= '
';
if (!empty($schedule_title)) {
$html .= '
' . esc_html($schedule_title) . ' ';
}
$html .= wp_kses_post($product_details_schedule);
$html .= '';
}
if (!empty($product_details_location) && is_array($product_details_location)) {
$url = esc_url($product_details_location['url']);
$title = esc_html($product_details_location['title']);
$target = esc_attr($product_details_location['target']);
$html .= '
';
if (!empty($location_title)) {
$html .= '
' . esc_html($location_title) . ' ';
}
$html .= '
';
$html .= '
';
}
if (!empty($product_details_certificate_image) && is_array($product_details_certificate_image)) {
$img_url = esc_url($product_details_certificate_image['url']);
$img_alt = esc_attr($product_details_certificate_image['alt']);
$html .= '
';
if (!empty($certificate_title)) {
$html .= '
' . esc_html($certificate_title) . ' ';
}
$html .= '
';
$html .= '
';
}
$html .= '
';
}
$html .= '
';
$html .= '
';
$html .= '
';
}
$html .= '
';
} else {
$html .= '
' . ($current_lang == 'de' ? 'Momentan keine öffentlichen Kurse. Frage nach einem maßgeschneiderten Inhouse-Training.' : 'No courses are currently available. Ask for a custom taylored inhouse training.' ) . '
';
}
wp_reset_postdata();
return ob_get_clean() . $html;
}
add_shortcode('our_products', 'custom_product_shortcode');
function register_email_master_post_type() {
$labels = array(
'name' => 'Email Template',
'singular_name' => 'emailtemplate',
'add_new' => 'Add New',
'add_new_item' => 'Add New Email Template',
'edit_item' => 'Edit Email Template',
'new_item' => 'New Email Template',
'view_item' => 'View Email Template',
'search_items' => 'Search Email Template',
'not_found' => 'No Email Template found',
'not_found_in_trash' => 'No Email Template found in Trash',
'menu_name' => 'Email Template'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'has_archive' => false,
'menu_icon' => 'dashicons-email-alt',
'supports' => array('title', 'excerpt', 'editor'),
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'emailtemplate',
'with_front' => false,
),
);
register_post_type('emailtemplate', $args);
}
add_action('init', 'register_email_master_post_type');
add_action('template_redirect', function () {
if (is_singular('emailtemplate')) {
wp_redirect(home_url());
exit;
}
});
/*add_filter('user_can_richedit', 'disable_visual_editor_for_emailtemplate');
function disable_visual_editor_for_emailtemplate($can) {
global $post;
if (is_admin() && $post && $post->post_type === 'emailtemplate') {
return false; // Disable visual editor
}
return $can;
}*/
function add_emailtemplate_shortcodes_metabox() {
add_meta_box(
'emailtemplate_shortcodes',
'Available Shortcodes',
'render_emailtemplate_shortcodes_metabox',
'emailtemplate',
'side',
'high'
);
}
add_action('add_meta_boxes', 'add_emailtemplate_shortcodes_metabox');
function render_emailtemplate_shortcodes_metabox($post) {
echo '
Use the following shortcodes in your email content:
';
echo '
';
echo '{{student_name}} - Student full name ';
echo '{{course_name}} - Purchased course title ';
echo '{{course_date}} - Course Date ';
echo '{{secret_url}} - Secret URL ';
echo '{{secret_pw}} - Secret URL password ';
echo '{{trainer_names}} - Assigned Trainers ';
echo '{{course_url}} - Link to the course ';
echo '{{site_name}} - Your website name ';
echo '{{year}} - Current year ';
echo '{{reminder_days_before}} - How many days before is a reminder email sent ';
echo ' ';
}
function register_trainer_post_type() {
$labels = array(
'name' => 'Trainers',
'singular_name' => 'Trainer',
'add_new' => 'Add New',
'add_new_item' => 'Add New Trainer',
'edit_item' => 'Edit Trainer',
'new_item' => 'New Trainer',
'view_item' => 'View Trainer',
'search_items' => 'Search Trainers',
'not_found' => 'No trainers found',
'not_found_in_trash' => 'No trainers found in Trash',
'menu_name' => 'Trainers'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-welcome-learn-more',
'supports' => array('title', 'thumbnail' , 'excerpt', 'editor'),
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'trainer',
'with_front' => false,
),
);
register_post_type('trainer', $args);
}
add_action('init', 'register_trainer_post_type');
function display_trainers_shortcode($atts) {
$query = new WP_Query(array(
'post_type' => 'trainer',
'posts_per_page' => -1,
));
if ($query->have_posts()) {
$output = '
';
while ($query->have_posts()) {
$query->the_post();
$output .= '
';
}
$output .= '
';
$output .= '
Your Trainers ';
wp_reset_postdata();
} else {
$output = '
No trainers found.
';
}
return $output;
}
add_shortcode('trainers', 'display_trainers_shortcode');
// Register Custom Post Type: Role Champion
function register_coaching_consulting_cpt() {
$labels = array(
'name' => 'Coaching',
'singular_name' => 'Coaching',
'menu_name' => 'Coaching',
'name_admin_bar' => 'Coaching',
'add_new' => 'Add New',
'add_new_item' => 'Add New Coaching',
'new_item' => 'New Coaching',
'edit_item' => 'Edit Coaching',
'view_item' => 'View Coaching',
'all_items' => 'All Coaching',
'search_items' => 'Search Coaching',
'not_found' => 'No Coaching found.',
'not_found_in_trash' => 'No Coaching found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'coaching-consulting','with_front'=>false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-learn-more',
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'taxonomies' => array('coaching_consulting_categories'),
'show_in_rest' => true,
);
register_post_type('coaching_consulting', $args);
}
add_action('init', 'register_coaching_consulting_cpt');
// Register Custom Taxonomy: Categories
function register_coaching_consulting_taxonomy() {
$labels = array(
'name' => 'Categories',
'singular_name' => 'Category',
'search_items' => 'Search Categories',
'all_items' => 'All Categories',
'parent_item' => 'Parent Category',
'parent_item_colon' => 'Parent Category:',
'edit_item' => 'Edit Category',
'update_item' => 'Update Category',
'add_new_item' => 'Add New Category',
'new_item_name' => 'New Category Name',
'menu_name' => 'Categories',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'coaching-consulting-category','with_front'=>false),
'show_in_rest' => true,
);
register_taxonomy('coaching_consulting_categories', array('coaching_consulting'), $args);
}
add_action('init', 'register_coaching_consulting_taxonomy');
function role_champion_shortcode($atts) {
ob_start();
$current_lang = pll_current_language();
// Adjust the taxonomy query
$query = new WP_Query(array(
'post_type' => 'coaching_consulting',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'coaching_consulting_categories',
'field' => 'slug',
'terms' => array('personal-development', 'personal-development-de'),
),
),
'lang' => $current_lang
));
if ($query->have_posts()) {
echo '
';
while ($query->have_posts()) {
$query->the_post();
$our_product_trainings_logo = get_field("our_product_trainings_logo");
?>
';
wp_reset_postdata();
// Owl Carousel Init
?>
No trainings found under Personal Development category.';
}
return ob_get_clean();
}
add_shortcode('role_champion', 'role_champion_shortcode');
function register_trainings_cpt() {
$taxonomy_labels = array(
'name' => 'Training Categories',
'singular_name' => 'Training Category',
'search_items' => 'Search Training Categories',
'all_items' => 'All Training Categories',
'parent_item' => 'Parent Training Category',
'parent_item_colon' => 'Parent Training Category:',
'edit_item' => 'Edit Training Category',
'update_item' => 'Update Training Category',
'add_new_item' => 'Add New Training Category',
'new_item_name' => 'New Training Category Name',
'menu_name' => 'Training Categories',
);
register_taxonomy('training_category', 'trainings', array(
'hierarchical' => true,
'labels' => $taxonomy_labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'training','with_front'=>false),
'show_in_rest' => true,
));
$labels = array(
'name' => 'Trainings',
'singular_name' => 'Training',
'menu_name' => 'Trainings',
'name_admin_bar' => 'Training',
'add_new' => 'Add New',
'add_new_item' => 'Add New Training',
'new_item' => 'New Training',
'edit_item' => 'Edit Training',
'view_item' => 'View Training',
'all_items' => 'All Trainings',
'search_items' => 'Search Trainings',
'not_found' => 'No Trainings found.',
'not_found_in_trash' => 'No Trainings found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'training/%training_category%', 'with_front'=>false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 6,
'menu_icon' => 'dashicons-welcome-learn-more',
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'taxonomies' => array('training_category'),
'show_in_rest' => true,
);
register_post_type('trainings', $args);
}
add_action('init', 'register_trainings_cpt');
function trainings_permalink_structure($permalink, $post) {
if ($post->post_type !== 'trainings') return $permalink;
$terms = wp_get_post_terms($post->ID, 'training_category');
if (!empty($terms) && !is_wp_error($terms)) {
$slug = $terms[0]->slug; // take first category
} else {
$slug = 'uncategorized'; // fallback
}
return str_replace('%training_category%', $slug, $permalink);
}
add_filter('post_type_link', 'trainings_permalink_structure', 10, 2);
add_action('init', 'completely_remove_woocommerce_blocks');
function completely_remove_woocommerce_blocks() {
// Remove block types
if (function_exists('unregister_block_type')) {
unregister_block_type('woocommerce/all-products');
unregister_block_type('woocommerce/product-best-sellers');
unregister_block_type('woocommerce/product-category');
unregister_block_type('woocommerce/product-new');
unregister_block_type('woocommerce/product-on-sale');
unregister_block_type('woocommerce/product-top-rated');
unregister_block_type('woocommerce/handpicked-products');
unregister_block_type('woocommerce/product-search');
unregister_block_type('woocommerce/featured-product');
unregister_block_type('woocommerce/cart');
unregister_block_type('woocommerce/checkout');
}
// Disable block editor in WooCommerce settings
add_filter('woocommerce_admin_disabled', '__return_true');
}
add_action('woocommerce_before_checkout_form', 'custom_participant_form_script',99);
function custom_participant_form_script() {
//if (is_admin() && !defined('DOING_AJAX')) return;
?>
cart->get_cart() as $cart_item) {
$qty = $cart_item['quantity'];
$product_id = $cart_item['product_id'];
for ($i = 1; $i <= $qty; $i++) {
if (empty($_POST["participant_{$product_id}_fname_$i"])) {
wc_add_notice(
pll__('error_participant_FirstName_missing') . ' ' .(int) $i,
'error'
);
}
if (empty($_POST["participant_{$product_id}_lname_$i"])) {
wc_add_notice(
pll__('error_participant_LastName_missing') . ' ' .(int) $i,
'error'
);
}
if (empty($_POST["participant_{$product_id}_email_$i"])) {
wc_add_notice(
pll__('error_participant_Email_missing') . ' ' .(int) $i,
'error'
);
}
}
}
}*/
add_action('woocommerce_checkout_process', 'validate_participant_fields');
function validate_participant_fields() {
foreach (WC()->cart->get_cart() as $cart_item) {
$qty = $cart_item['quantity'];
$product_id = $cart_item['product_id'];
for ($i = 1; $i <= $qty; $i++) {
if (empty($_POST["participant_{$product_id}_fname_$i"])) {
wc_add_notice(
pll__('error_participant_FirstName_missing') . ' ' . (int) $i,
'error'
);
add_filter('woocommerce_checkout_fields', function ($fields) use ($product_id, $i) {
$fields['billing']["participant_{$product_id}_fname_$i"]['class'][] = 'error_class';
return $fields;
});
}
if (empty($_POST["participant_{$product_id}_lname_$i"])) {
wc_add_notice(
pll__('error_participant_LastName_missing') . ' ' . (int) $i,
'error'
);
add_filter('woocommerce_checkout_fields', function ($fields) use ($product_id, $i) {
$fields['billing']["participant_{$product_id}_lname_$i"]['class'][] = 'error_class';
return $fields;
});
}
if (empty($_POST["participant_{$product_id}_email_$i"])) {
wc_add_notice(
pll__('error_participant_Email_missing') . ' ' . (int) $i,
'error'
);
add_filter('woocommerce_checkout_fields', function ($fields) use ($product_id, $i) {
$fields['billing']["participant_{$product_id}_email_$i"]['class'][] = 'error_class';
return $fields;
});
}
}
}
}
add_action('woocommerce_checkout_create_order', 'save_participant_fields_to_order', 10, 2);
function save_participant_fields_to_order($order, $data) {
foreach (WC()->cart->get_cart() as $cart_item) {
$qty = $cart_item['quantity'];
$product_id = $cart_item['product_id'];
$participant_data = [];
for ($i = 1; $i <= $qty; $i++) {
$fname = sanitize_text_field($_POST["participant_{$product_id}_fname_$i"]);
$lname = sanitize_text_field($_POST["participant_{$product_id}_lname_$i"]);
$email = sanitize_email($_POST["participant_{$product_id}_email_$i"]);
$phone = sanitize_text_field($_POST["participant_{$product_id}_phone_$i"]);
$participant_data[] = [
'fname' => $fname,
'lname' => $lname,
'phone' => $phone,
'email' => $email
];
}
if (!empty($_POST['subscribe_to_newsletter'])) {
// my_mailchimp_subscribe($email, $fname, ['webSite.Newsletter']);
$api_key = 'c3f7744bc3eae2494cc9aa722c560bb1-us1';
$audience_id = 'a75a524fd0';
$tagName = 'webSite.Newsletter';
$dc = substr($api_key, strpos($api_key, '-') + 1);
$url = "https://{$dc}.api.mailchimp.com/3.0/lists/{$audience_id}/members";
$body = [
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname .' '.$lname,
]
];
$response = wp_remote_post($url, [
'headers' => [
'Authorization' => 'apikey ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode($body)
]);
/** ------------------------------
* Add tag: webSite.Newsletter
* ------------------------------ */
$subscriber_hash = md5(strtolower($email));
wp_remote_post(
"https://{$dc}.api.mailchimp.com/3.0/lists/{$audience_id}/members/{$subscriber_hash}/tags",
[
'headers' => [
'Authorization' => 'apikey ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode([
'tags' => [
['name' => $tagName, 'status' => 'active']
]
])
]
);
}
// Save as order meta
$order->update_meta_data("_participants_{$product_id}", $participant_data);
}
}
add_action('woocommerce_thankyou', 'show_participant_data_in_admin');
add_action('woocommerce_admin_order_data_after_order_details', 'show_participant_data_in_admin');
function show_participant_data_in_admin($order) {
if (is_numeric($order)) {
$order = wc_get_order($order);
}
if (!$order instanceof WC_Order) {
return;
}
foreach ($order->get_meta_data() as $meta) {
if (strpos($meta->key, '_participants_') === 0 && is_array($meta->value)) {
$product_id = str_replace('_participants_', '', $meta->key);
$product = wc_get_product($product_id);
$product_name = $product ? $product->get_name() : 'Unknown Course';
echo '
';
echo pll_e('Participant');
echo " ";
echo pll_e('for_Course');
echo ': ' . esc_html($product_name) . ' ';
foreach ($meta->value as $i => $participant) {
echo '
';
echo pll_e('Participant');
echo ' ' . ($i + 1) . ' ';
echo pll_e('participant_FirstName').': ' . esc_html($participant['fname']) . ' ';
echo pll_e('participant_LastName').': ' . esc_html($participant['lname']) . ' ';
echo pll_e('participant_Email').': ' . esc_html($participant['email']) . ' ';
echo pll_e('participant_PPhone').': ' . esc_html($participant['phone']) . '
';
}
}
}
}
add_action('woocommerce_thankyou', 'send_custom_new_order_emails', 10, 1);
//this function also triggers an email-reminder 10 days before the training
function send_custom_new_order_emails($order_id) {
if (!$order_id) return;
$order = wc_get_order($order_id);
$email_sent = $order->get_meta( '_thankyou_email_sent' );
if ( ! $email_sent ) {
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$product_id = $product->get_id();
$pakey = "_participants_".$product_id;
$participants_array = $order->get_meta($pakey);
//Immediate Welcome Email
$emailtemplate_post_id = get_field('participate_email_template', $product_id);
$participant_subject = "";
$email_body = "";
if ($emailtemplate_post_id) {
$emailtemplate_post = get_post($emailtemplate_post_id);
$email_body = $emailtemplate_post->post_content;
$participant_subject = $emailtemplate_post->post_excerpt;
}
//10 day before training reminder
$REMINDER_DAYS_BEFORE = 10;
$reminder_email_template_post_id = get_field('participate_reminder_email_template', $product_id);
$reminder_participant_subject = "";
$reminder_email_body = "";
if ($reminder_email_template_post_id) {
$reminder_email_template_post = get_post($reminder_email_template_post_id);
$reminder_email_body = $reminder_email_template_post->post_content;
$reminder_participant_subject = $reminder_email_template_post->post_excerpt;
}
$product_name = $product ? $product->get_name() : 'Unknown Course';
$data = maybe_unserialize( $participants_array ); // WordPress safe way to unserialize
if ( is_array($data) ) {
$course_url = get_permalink($product_id);
$course_date = get_field('product_date', $product_id);
$secret_url = get_field('secret_page_url', $product_id);
$secret_pw = get_field('secret_page_password', $product_id);
$our_trainer = get_field('our_trainer',$product_id);
$trainer_names = '';
foreach($our_trainer as $tr) {
$trainer_names .= $tr->post_title . ', ';
}
$trainer_names = rtrim($trainer_names, ', ');
$site_name = get_bloginfo('name');
$year = date('Y');
foreach ( $data as $entry ) {
if ( isset($entry['email']) ) {
$participant_email = $entry['email'];
$student_name = trim(($entry['fname'] ?? '') . ' ' . ($entry['lname'] ?? ''));
$replacements = array(
'{{student_name}}' => $student_name,
'{{course_name}}' => $product_name,
'{{course_url}}' => $course_url,
'{{site_name}}' => $site_name,
'{{year}}' => $year,
'{{course_date}}' => $course_date,
'{{secret_url}}' => $secret_url,
'{{secret_pw}}' => $secret_pw,
'{{trainer_names}}' => $trainer_names,
'{{reminder_days_before}}' => $REMINDER_DAYS_BEFORE
);
$individual_email_body = strtr($email_body, $replacements);
wp_mail($participant_email, $participant_subject, $individual_email_body, ['Content-Type: text/html; charset=UTF-8']);
$individual_reminder_email_body = strtr($reminder_email_body, $replacements);
schedule_training_reminder_mail($REMINDER_DAYS_BEFORE, $course_date, $participant_email, $reminder_participant_subject, $individual_reminder_email_body,$order_id);
}
}
}
}
if ($order->get_payment_method() === 'bacs' && $order->get_status() === 'on-hold') {
$order->set_status('processing'); // No email sent
}
$order->update_meta_data( '_thankyou_email_sent', '1' );
$order->save();
}
/*foreach ($order->get_meta_data() as $meta) {
if (strpos($meta->key, '_participants_') === 0 && is_array($meta->value)) {
$product_id = str_replace('_participants_', '', $meta->key);
$product = wc_get_product($product_id);
$emailtemplate_post_id = get_field('participate_email_template', $product_id);
$participant_subject = "";
$email_body = "";
if ($emailtemplate_post_id) {
$emailtemplate_post = get_post($emailtemplate_post_id);
$email_body = $emailtemplate_post->post_content;
$participant_subject = $emailtemplate_post->post_title;
// Now you can use $email_body, $email_title
}
$product_name = $product ? $product->get_name() : 'Unknown Course';
foreach ($meta->value as $i => $participant) {
echo '
Participant ' . ($i + 1) . ' ';
echo 'First Name: ' . esc_html($participant['fname']) . ' ';
echo 'Last Name: ' . esc_html($participant['lname']) . ' ';
echo 'Email: ' . esc_html($participant['email']) . ' ';
echo 'Phone: ' . esc_html($participant['phone']) . '
';
$participant_email = $participant['email'];
wp_mail($participant_email, $participant_subject, $email_body, ['Content-Type: text/html; charset=UTF-8']);
}
//$customer_message = generate_custom_email_template($order, 'customer');
}
}*/
// Customer email
}
function schedule_training_reminder_mail($reminder_days_before, $course_date, $to, $subject, $body,$order_id) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return; // order not found
}
$excluded_statuses = array( 'cancelled', 'on-hold', 'pending' );
$current_status = $order->get_status();
if ( ! in_array( $current_status, $excluded_statuses, true ) ) {
$reminder_hour_local = '9:00';
$reminder_tz = 'Europe/Berlin';
$course_date = trim((string) $course_date);
$timestamp = null;
try {
$tz = new DateTimeZone($reminder_tz);
// $course_date is defined in a ACF to come in format d/m/Y, e.g. "28/10/2025"
$dt = DateTime::createFromFormat('d/m/Y H:i', $course_date . ' ' . $reminder_hour_local, $tz);
$dt->modify('-' . $reminder_days_before . ' days');
$timestamp = $dt->getTimestamp();
} catch (Throwable $e) {
error_log('Error parsing course date: ' . print_r($course_date, true) . ' --> ' .$e);
return;
}
$args = [$to, $subject, $body];
if ($timestamp <= time()) {
//don't send an extra reminder when date of booking is less than 10 days before the training
} elseif (!wp_next_scheduled('send_reminder_mail', $args)) {
wp_schedule_single_event($timestamp, 'send_reminder_mail', $args);
}
}
}
add_action(
'send_reminder_mail',
function($to, $subject, $html_body) {
wp_mail($to, $subject, $html_body, ['Content-Type: text/html; charset=UTF-8']);
},
10, // standard priority
3 // function takes 3 arguments
);
function generate_custom_email_template($order, $recipient_type = 'admin') {
ob_start();
include get_stylesheet_directory() . '/woocommerce/emails/custom-new-order-email.php';
return ob_get_clean();
}
add_action('woocommerce_checkout_before_order_review_heading','add_wraper_review_order');
function add_wraper_review_order(){
echo '
';
echo pll_e('participant_OrderSummary');
echo ' ';
}
add_action('woocommerce_checkout_after_order_review','complete_wraper_review_order');
function complete_wraper_review_order(){
echo '
';
}
add_action( 'woocommerce_review_order_after_cart_contents', 'custom_checkout_coupon_form', 20 );
function custom_checkout_coupon_form() {
if ( wc_coupons_enabled() ) {
echo '
';
echo '';
wc_get_template( 'checkout/form-coupon.php' );
echo ' ';
echo ' ';
}
}
function custom_scroll_script() {
?>
false,
'message' => $errorMsg
]);
}
$api_key = 'c3f7744bc3eae2494cc9aa722c560bb1-us1';
$audience_id = 'a75a524fd0';
$tagName = 'webSite.Newsletter';
$dc = substr($api_key, strpos($api_key, '-') + 1);
$url = "https://{$dc}.api.mailchimp.com/3.0/lists/{$audience_id}/members";
$body = [
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $name,
]
];
$response = wp_remote_post($url, [
'headers' => [
'Authorization' => 'apikey ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode($body)
]);
/** ------------------------------
* Add tag: webSite.Newsletter
* ------------------------------ */
$subscriber_hash = md5(strtolower($email));
wp_remote_post(
"https://{$dc}.api.mailchimp.com/3.0/lists/{$audience_id}/members/{$subscriber_hash}/tags",
[
'headers' => [
'Authorization' => 'apikey ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode([
'tags' => [
['name' => $tagName, 'status' => 'active']
]
])
]
);
$successMsg = 'Subscribed successfully!';
if ($lang === 'de' || $lang === 'de_DE') {
$successMsg = 'Erfolgreich abonniert!';
}
wp_send_json([
'success' => true,
'message' => $successMsg
]);
}
add_filter( 'woocommerce_page_title', 'custom_woocommerce_shop_page_title');
function custom_woocommerce_shop_page_title( $page_title ) {
if ( is_shop() ) {
return ($current_lang == 'de' ? 'Alle Trainings' : 'All trainings' );
}
return $page_title;
}
add_action('init', function () {
if (function_exists('pll_register_string')) {
pll_register_string('participant_data', 'Participant Data', 'WordPress');
pll_register_string('participant', 'Participant', 'WordPress');
pll_register_string('participant_FirstName', 'participant_FirstName', 'WordPress');
pll_register_string('participant_LastName', 'participant_LastName', 'WordPress');
pll_register_string('participant_PPhone', 'participant_PPhone', 'WordPress');
pll_register_string('participant_Email', 'participant_Email', 'WordPress');
pll_register_string('participant_SameasBillinginfo', 'participant_SameasBillinginfo', 'WordPress');
pll_register_string('participant_OrderSummary', 'participant_OrderSummary', 'WordPress');
pll_register_string('for_Course', 'for_Course', 'WordPress');
pll_register_string('days', 'days', 'WordPress');
pll_register_string('book_now', 'book_now', 'WordPress');
pll_register_string('added', 'added', 'WordPress');
pll_register_string('error_participant_FirstName_missing', 'error_participant_FirstName_missing', 'WordPress');
pll_register_string('error_participant_LastName_missing', 'error_participant_LastName_missing', 'WordPress');
pll_register_string('error_participant_Email_missing', 'error_participant_Email_missing', 'WordPress');
pll_register_string('training_delivery_method_in_person', 'training_delivery_method_in_person', 'WordPress');
}
});
add_filter('woocommerce_order_item_name', 'add_custom_fields_after_title', 10, 3);
function add_custom_fields_after_title($item_name, $item, $is_visible) {
if (!is_order_received_page()) {
return $item_name;
}
$product = $item->get_product();
if (!$product) return $item_name;
$product_id = $product->get_id();
// Get custom fields
$training_course = get_field('training_course', $product_id);
$days = get_field('days', $product_id);
$product_date_raw = get_field('product_date', $product_id);
$language_name = get_field('language_name', $product_id);
$method = get_field('method', $product_id);
$custom_html = '';
// Format date range if available
if ($product_date_raw && $days) {
$start_date = DateTime::createFromFormat('d/m/Y', $product_date_raw);
if ($start_date) {
$end_date = clone $start_date;
$end_date->modify('+' . ($days - 1) . ' days');
$custom_html .= '
';
$custom_html .= $start_date->format('d M.') . ' ' . $start_date->format('Y') . ' - ';
$custom_html .= $end_date->format('d M.') . ' ' . $end_date->format('Y');
$custom_html .= ' ';
}
}
return $item_name . $custom_html;
}
function individual_trainers_shortcode($atts) {
ob_start();
$atts = shortcode_atts(array(
'id' => '',
), $atts, 'individual_trainers_shortcode');
$ids = array();
if (!empty($atts['id'])) {
$ids = array_map('intval', explode(',', $atts['id']));
}
$args = array(
'post_type' => 'trainer',
'posts_per_page' => 10,
'post_status' => 'publish',
);
if (!empty($ids)) {
$args['post__in'] = $ids;
$args['orderby'] = 'post__in'; // preserve order
}
$query = new WP_Query($args);
if ($query->have_posts()) {
echo "
";
echo "
";
while ($query->have_posts()) {
$query->the_post();
global $post;
echo "
';
}
echo '
';
while ($query->have_posts()) {
$query->the_post();
global $post;
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo "
" . get_the_post_thumbnail($post->ID, 'full') . "
";
echo "
";
echo "
" . esc_html(get_the_title()) . " ";
echo "
";
echo apply_filters('the_content', get_the_content());
echo "
";
echo '
';
$heading = get_field('heading', $post->ID);
if (!empty($heading)) {
echo '
' . esc_html($heading) . ' ';
}
echo "
LinkedIN ";
echo "
";
echo '
';
echo '
';
echo '
';
}
echo "
";
wp_reset_postdata();
} else {
echo "
No trainers found.
";
}
return ob_get_clean();
}
add_shortcode('individual_trainers', 'individual_trainers_shortcode');
add_filter( 'manage_trainings_posts_columns', 'add_trainings_id_column_first' );
function add_trainings_id_column_first( $columns ) {
$new = [];
foreach ( $columns as $key => $value ) {
$new[$key] = $value;
if ( $key === 'cb' ) {
$new['trainings_id'] = 'Trainings ID';
}
}
return $new;
}
add_action( 'manage_trainings_posts_custom_column', 'show_trainings_id_column', 10, 2 );
function show_trainings_id_column( $column, $post_id ) {
if ( $column === 'trainings_id' ) {
echo $post_id;
}
}
add_filter( 'manage_edit-trainings_sortable_columns', 'make_trainings_id_column_sortable' );
function make_trainings_id_column_sortable( $columns ) {
$columns['trainings_id'] = 'ID';
return $columns;
}
add_filter('acf/fields/post_object/result', 'my_acf_post_object_result', 10, 4);
function my_acf_post_object_result( $title, $post, $field, $post_id ) {
$title .= ' (ID: ' . $post->ID . ')';
return $title;
}
// Add "Subscribe to our newsletter" checkbox on checkout page
add_action('woocommerce_review_order_before_submit', 'add_newsletter_checkbox_to_checkout', 9);
function add_newsletter_checkbox_to_checkout() {
// Detect current language using Polylang
$current_lang = function_exists('pll_current_language') ? pll_current_language() : 'en';
// Translated labels
$label_texts = [
'en' => 'Subscribe to our newsletter',
'de' => 'Abonnieren Sie unseren Newsletter'
];
$label = isset($label_texts[$current_lang]) ? $label_texts[$current_lang] : $label_texts['en'];
// Output checkbox field (remove "(optional)" automatically)
echo '
';
echo '';
echo ' ';
echo '' . esc_html($label) . ' ';
echo ' ';
echo '
';
}
// Save checkbox value to order meta
add_action('woocommerce_checkout_update_order_meta', 'save_newsletter_checkbox_value');
function save_newsletter_checkbox_value($order_id) {
if (!empty($_POST['subscribe_to_newsletter'])) {
update_post_meta($order_id, '_subscribe_to_newsletter', 'yes');
} else {
update_post_meta($order_id, '_subscribe_to_newsletter', 'no');
}
}
// Display in admin order details
add_action('woocommerce_admin_order_data_after_billing_address', 'display_newsletter_checkbox_in_admin', 10, 1);
function display_newsletter_checkbox_in_admin($order) {
$subscribed = get_post_meta($order->get_id(), '_subscribe_to_newsletter', true);
echo '
' . __('Newsletter Subscription', 'woocommerce') . ': ' . ($subscribed === 'yes' ? __('Yes', 'woocommerce') : __('No', 'woocommerce')) . '
';
}
add_filter('woocommerce_page_title', function($page_title) {
// Only change on shop page
if ( is_shop() ) {
// Detect language via Polylang if available
$current_lang = function_exists('pll_current_language') ? pll_current_language() : '';
if ( $current_lang === 'de' ) {
return 'Alle Trainings';
}
// For English or other, keep the default (All trainings)
}
return $page_title;
});
add_action('wp_footer', function() {
if(is_shop()) {
?>
posts) && empty($wp_query->posts)) {
// Only output this HTML when there are no English products in WooCommerce loop
echo wp_kses_post(
'
We do not have any English public trainings scheduled right now. Our German training options are available
here .
'
);
}
}
}
add_action('woocommerce_no_products_found', 'gm_custom_wc_no_products_found_html', 5);
add_filter('woocommerce_get_order_item_totals', function($totals, $order) {
$subtotal = floatval($order->get_subtotal());
$discount = floatval($order->get_total_discount());
$new_subtotal = $subtotal - $discount;
if (isset($totals['cart_subtotal'])) {
$totals['cart_subtotal']['value'] = wc_price($new_subtotal, ['currency' => $order->get_currency()]);
}
if (isset($totals['discount']) && isset($totals['cart_subtotal'])) {
$new_order = [];
$new_order['discount'] = $totals['discount'];
$new_order['cart_subtotal'] = $totals['cart_subtotal'];
foreach ($totals as $key => $row) {
if (!in_array($key, ['discount','cart_subtotal'])) {
$new_order[$key] = $row;
}
}
$totals = $new_order;
}
return $totals;
}, 20, 2);
add_action('pre_get_posts', 'my_shop_order_by_product_date', PHP_INT_MAX);
function my_shop_order_by_product_date($query) {
if (! $query->is_main_query()) {
return;
}
if (is_shop() || is_post_type_archive('product') || is_product_category() || is_product_tag()) {
// Respect user-selected orderby
if (! empty($_GET['orderby'])) {
return;
}
// Today's date in YYYYMMDD format
$today = date('Ymd');
$query->set('meta_key', 'product_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
// Exclude past dates
$meta_query = $query->get('meta_query');
if (! is_array($meta_query)) {
$meta_query = [];
}
$meta_query[] = [
'key' => 'product_date',
'value' => $today,
'compare' => '>=',
'type' => 'NUMERIC',
];
$query->set('meta_query', $meta_query);
}
}
add_filter('woof_products_query', 'my_woof_order_by_product_date', PHP_INT_MAX, 1);
function my_woof_order_by_product_date($args) {
if (! empty($_GET['orderby'])) {
return $args;
}
$today = date('Ymd');
$args['meta_key'] = 'product_date';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
if (! isset($args['meta_query']) || ! is_array($args['meta_query'])) {
$args['meta_query'] = [];
}
$args['meta_query'][] = [
'key' => 'product_date',
'value' => $today,
'compare' => '>=',
'type' => 'NUMERIC',
];
return $args;
}
add_action('woocommerce_before_checkout_form', 'custom_coupon_wrapper_start', 5);
function custom_coupon_wrapper_start() {
echo '
';
}
add_action('woocommerce_before_checkout_form', 'custom_coupon_wrapper_end', 15);
function custom_coupon_wrapper_end() {
echo '
';
}