admin_url('admin-ajax.php'), )); } add_action('wp_enqueue_scripts', 'enqueue_custom_ajax_add_to_cart'); function woof_custom_log($message, $data = []) { $log_file = WP_CONTENT_DIR . '/woof-acf-log.log'; // logs to wp-content/woof-acf-log.log $time = date('[Y-m-d H:i:s]'); $output = $time . ' ' . $message; if (!empty($data)) { $output .= ' - ' . print_r($data, true); } file_put_contents($log_file, $output . PHP_EOL, FILE_APPEND); } add_action('wp_footer','product_listing_script',9999); function product_listing_script(){ if (is_shop() || is_product_category() || is_product_tag() || is_post_type_archive('product') || is_singular('trainings') || is_page('product-ownership-path') || is_page('product-ownership-path-2') || is_tax('training_category') ) { if ( function_exists('pll_current_language') ) { $current_lang = pll_current_language(); }else{ $current_lang = 'en'; } ?> cart->add_to_cart($product_id, $quantity)) { do_action('woocommerce_ajax_added_to_cart', $product_id); WC_AJAX::get_refreshed_fragments(); } else { $data = array( 'error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id) ); echo wp_send_json($data); } wp_die(); } add_filter( 'woocommerce_cart_item_name', 'show_custom_field_in_cart', 10, 3 ); function show_custom_field_in_cart( $product_name, $cart_item, $cart_item_key ) { if ( isset( $cart_item['product_id'] ) ) { $product_id = $cart_item['product_id']; $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); 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'); $product_name = '' . $start_date->format('d M.') . ' ' . $start_date->format('Y') . ' - ' . $end_date->format('d M.') . ' ' . $end_date->format('Y') . ''; //$html .= '