// NordicCommerce Pro - Enhanced Performance & SEO Features // ======================================================= // Include performance optimization class require_once get_template_directory() . '/inc/performance.php'; // Include schema markup system require_once get_template_directory() . '/inc/schema.php'; /** * Enqueue optimized stylesheets and scripts */ function nordiccommerce_enqueue_assets() { // Main stylesheet (non-critical, loaded asynchronously) wp_enqueue_style( 'nordiccommerce-main', get_template_directory_uri() . '/assets/css/main.min.css', array(), wp_get_theme()->get('Version') ); // Main JavaScript (deferred) wp_enqueue_script( 'nordiccommerce-main', get_template_directory_uri() . '/assets/js/main.min.js', array(), wp_get_theme()->get('Version'), true // Load in footer ); // Localize script with AJAX data wp_localize_script('nordiccommerce-main', 'nordicCommerce', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('nordiccommerce_nonce'), 'isWooCommerce' => class_exists('WooCommerce'), 'cartUrl' => class_exists('WooCommerce') ? wc_get_cart_url() : '', 'checkoutUrl' => class_exists('WooCommerce') ? wc_get_checkout_url() : '' )); } add_action('wp_enqueue_scripts', 'nordiccommerce_enqueue_assets'); /** * Add preload links for critical resources */ function nordiccommerce_resource_hints($urls, $relation_type) { if ('preload' === $relation_type) { // Preload Inter variable font $urls[] = array( 'href' => get_template_directory_uri() . '/assets/fonts/inter-var.woff2', 'as' => 'font', 'type' => 'font/woff2', 'crossorigin' => 'anonymous' ); } if ('dns-prefetch' === $relation_type) { $urls[] = 'https://fonts.googleapis.com'; $urls[] = 'https://www.google-analytics.com'; if (is_woocommerce() || is_cart() || is_checkout()) { $urls[] = 'https://js.stripe.com'; } } return $urls; } add_filter('wp_resource_hints', 'nordiccommerce_resource_hints', 10, 2); /** * Add theme support for WooCommerce and performance features */ function nordiccommerce_theme_support() { // WooCommerce support add_theme_support('woocommerce'); add_theme_support('wc-product-gallery-zoom'); add_theme_support('wc-product-gallery-lightbox'); add_theme_support('wc-product-gallery-slider'); // HTML5 support add_theme_support('html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style' )); // Featured images add_theme_support('post-thumbnails'); // Custom logo add_theme_support('custom-logo', array( 'height' => 60, 'width' => 300, 'flex-height' => true, 'flex-width' => true )); // Title tag support add_theme_support('title-tag'); // Responsive embeds add_theme_support('responsive-embeds'); // Wide alignment add_theme_support('align-wide'); // Custom line height add_theme_support('custom-line-height'); // Custom units add_theme_support('custom-units'); } add_action('after_setup_theme', 'nordiccommerce_theme_support'); /** * Register navigation menus */ function nordiccommerce_register_menus() { register_nav_menus(array( 'primary' => esc_html__('Primary Menu', 'nordiccommerce'), 'footer' => esc_html__('Footer Menu', 'nordiccommerce'), 'mobile' => esc_html__('Mobile Menu', 'nordiccommerce') )); } add_action('init', 'nordiccommerce_register_menus'); /** * Enhanced WooCommerce cart fragments for AJAX updates */ function nordiccommerce_cart_fragments($fragments) { // Cart count $cart_count = WC()->cart ? WC()->cart->get_cart_contents_count() : 0; $fragments['.cart-count'] = '' . esc_html($cart_count) . ''; // Cart total $cart_total = WC()->cart ? WC()->cart->get_cart_total() : ''; $fragments['.cart-total'] = '' . wp_kses_post($cart_total) . ''; return $fragments; } add_filter('woocommerce_add_to_cart_fragments', 'nordiccommerce_cart_fragments'); /** * AJAX add to cart handler */ function nordiccommerce_ajax_add_to_cart() { // Verify nonce if (\!wp_verify_nonce($_POST['nonce'], 'nordiccommerce_nonce')) { wp_die('Security check failed'); } $product_id = absint($_POST['product_id']); $quantity = absint($_POST['quantity']); if ($product_id && $quantity) { $result = WC()->cart->add_to_cart($product_id, $quantity); if ($result) { wp_send_json_success(array( 'cart_count' => WC()->cart->get_cart_contents_count(), 'cart_total' => WC()->cart->get_cart_total(), 'message' => 'Product added to cart\!' )); } else { wp_send_json_error(array( 'message' => 'Failed to add product to cart.' )); } } else { wp_send_json_error(array( 'message' => 'Invalid product data.' )); } } add_action('wp_ajax_add_to_cart', 'nordiccommerce_ajax_add_to_cart'); add_action('wp_ajax_nopriv_add_to_cart', 'nordiccommerce_ajax_add_to_cart'); /** * Add custom meta tags for SEO and social sharing */ function nordiccommerce_meta_tags() { // Open Graph tags echo '' . "\n"; echo '' . "\n"; if (is_product()) { global $product; if ($product) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; $image_id = $product->get_image_id(); if ($image_id) { $image_url = wp_get_attachment_image_url($image_id, 'large'); echo '' . "\n"; } // Product-specific tags echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } } else { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; if (is_singular()) { $excerpt = get_the_excerpt(); if ($excerpt) { echo '' . "\n"; } if (has_post_thumbnail()) { $image_url = get_the_post_thumbnail_url(null, 'large'); echo '' . "\n"; } } } // Twitter Card tags echo '' . "\n"; if (get_option('nordiccommerce_twitter_handle')) { echo '' . "\n"; } } add_action('wp_head', 'nordiccommerce_meta_tags'); /** * Add theme customizer options */ function nordiccommerce_customize_register($wp_customize) { // Performance Section $wp_customize->add_section('nordiccommerce_performance', array( 'title' => 'Performance Settings', 'priority' => 30 )); // Enable/disable optimizations $wp_customize->add_setting('nordiccommerce_remove_jquery', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' )); $wp_customize->add_control('nordiccommerce_remove_jquery', array( 'label' => 'Remove jQuery (Recommended)', 'section' => 'nordiccommerce_performance', 'type' => 'checkbox' )); // Social Media Section $wp_customize->add_section('nordiccommerce_social', array( 'title' => 'Social Media', 'priority' => 40 )); // Social media URLs $social_platforms = array( 'facebook' => 'Facebook URL', 'twitter' => 'Twitter URL', 'instagram' => 'Instagram URL', 'linkedin' => 'LinkedIn URL' ); foreach ($social_platforms as $platform => $label) { $wp_customize->add_setting("nordiccommerce_{$platform}_url", array( 'default' => '', 'sanitize_callback' => 'esc_url_raw' )); $wp_customize->add_control("nordiccommerce_{$platform}_url", array( 'label' => $label, 'section' => 'nordiccommerce_social', 'type' => 'url' )); } } add_action('customize_register', 'nordiccommerce_customize_register'); /** * Add body classes for styling hooks */ function nordiccommerce_body_classes($classes) { // Add browser detection if (is_admin_bar_showing()) { $classes[] = 'admin-bar-showing'; } // Add device detection if (wp_is_mobile()) { $classes[] = 'mobile-device'; } // Add WooCommerce context if (class_exists('WooCommerce')) { if (is_woocommerce()) { $classes[] = 'woocommerce-page'; } if (is_cart()) { $classes[] = 'cart-page'; } if (is_checkout()) { $classes[] = 'checkout-page'; } } return $classes; } add_filter('body_class', 'nordiccommerce_body_classes'); /** * Optimize WooCommerce performance */ function nordiccommerce_optimize_woocommerce() { if (\!class_exists('WooCommerce')) { return; } // Disable WooCommerce scripts on non-shop pages if (\!is_woocommerce() && \!is_cart() && \!is_checkout() && \!is_account_page()) { wp_dequeue_style('woocommerce-general'); wp_dequeue_style('woocommerce-layout'); wp_dequeue_style('woocommerce-smallscreen'); wp_dequeue_script('wc-cart-fragments'); wp_dequeue_script('woocommerce'); } } add_action('wp_enqueue_scripts', 'nordiccommerce_optimize_woocommerce', 99); /** * Core Web Vitals optimization */ function nordiccommerce_core_web_vitals() { // Add fetchpriority to hero images add_filter('wp_get_attachment_image_attributes', function($attr, $attachment, $size) { if (is_front_page() && (strpos($size, 'hero') \!== false || strpos($size, 'banner') \!== false)) { $attr['fetchpriority'] = 'high'; $attr['loading'] = 'eager'; } return $attr; }, 10, 3); // Optimize images with better attributes add_filter('wp_get_attachment_image_attributes', function($attr) { if (\!isset($attr['loading'])) { $attr['loading'] = 'lazy'; } $attr['decoding'] = 'async'; return $attr; }); } add_action('init', 'nordiccommerce_core_web_vitals'); EOF < /dev/null // Include AI optimization class require_once get_template_directory() . '/inc/ai-optimization.php'; /** * Enhanced SEO features for better search engine understanding */ function nordiccommerce_enhanced_seo() { // Add JSON-LD structured data for homepage if (is_front_page()) { add_action('wp_head', function() { $schema = array( '@context' => 'https://schema.org', '@type' => 'WebSite', 'name' => get_bloginfo('name'), 'url' => home_url(), 'description' => get_bloginfo('description'), 'publisher' => array( '@type' => 'Organization', 'name' => get_bloginfo('name'), 'logo' => array( '@type' => 'ImageObject', 'url' => get_theme_mod('custom_logo') ? wp_get_attachment_image_url(get_theme_mod('custom_logo'), 'full') : get_template_directory_uri() . '/assets/images/logo.png' ) ) ); echo '' . "\n"; }); } // Enhanced meta tags for products if (is_product()) { add_action('wp_head', function() { global $product; if (\!$product) return; // Additional product meta tags echo '' . "\n"; echo '' . "\n"; // Google Shopping attributes echo '' . "\n"; // Add verification code // Rich snippets $categories = get_the_terms($product->get_id(), 'product_cat'); if ($categories && \!is_wp_error($categories)) { $category_names = array_map(function($cat) { return $cat->name; }, $categories); echo '' . "\n"; } }); } } add_action('init', 'nordiccommerce_enhanced_seo'); /** * Add custom robots.txt for better AI crawling */ function nordiccommerce_custom_robots() { if (is_admin() || \!is_robots()) { return; } $robots_content = "User-agent: *\n"; $robots_content .= "Allow: /\n"; $robots_content .= "Allow: /wp-content/uploads/\n"; $robots_content .= "Disallow: /wp-admin/\n"; $robots_content .= "Disallow: /wp-includes/\n"; $robots_content .= "Disallow: /wp-json/\n"; $robots_content .= "Disallow: /?s=*\n"; $robots_content .= "Disallow: */feed/\n"; $robots_content .= "Disallow: */trackback/\n"; $robots_content .= "Disallow: */attachment/\n"; $robots_content .= "\n"; // AI-specific crawlers $robots_content .= "User-agent: GPTBot\n"; $robots_content .= "Allow: /\n"; $robots_content .= "Crawl-delay: 1\n"; $robots_content .= "\n"; $robots_content .= "User-agent: Claude-Web\n"; $robots_content .= "Allow: /\n"; $robots_content .= "Crawl-delay: 1\n"; $robots_content .= "\n"; $robots_content .= "User-agent: CCBot\n"; $robots_content .= "Allow: /\n"; $robots_content .= "Crawl-delay: 1\n"; $robots_content .= "\n"; // Sitemap $robots_content .= "Sitemap: " . home_url('/sitemap.xml') . "\n"; header('Content-Type: text/plain; charset=utf-8'); echo $robots_content; exit; } add_action('do_robots', 'nordiccommerce_custom_robots'); /** * Generate XML sitemap for better indexing */ function nordiccommerce_generate_sitemap() { if (get_query_var('sitemap')) { header('Content-Type: application/xml; charset=utf-8'); echo '' . "\n"; echo '' . "\n"; // Homepage echo '' . "\n"; echo '' . esc_url(home_url('/')) . '' . "\n"; echo '' . date('Y-m-d\TH:i:s+00:00') . '' . "\n"; echo 'daily' . "\n"; echo '1.0' . "\n"; echo '' . "\n"; // Products $products = get_posts(array( 'post_type' => 'product', 'post_status' => 'publish', 'numberposts' => -1 )); foreach ($products as $product_post) { $product = wc_get_product($product_post->ID); if (\!$product || \!$product->is_visible()) continue; echo '' . "\n"; echo '' . esc_url(get_permalink($product_post->ID)) . '' . "\n"; echo '' . date('Y-m-d\TH:i:s+00:00', strtotime($product_post->post_modified)) . '' . "\n"; echo 'weekly' . "\n"; echo '0.8' . "\n"; // Product images $image_id = $product->get_image_id(); if ($image_id) { $image_url = wp_get_attachment_image_url($image_id, 'full'); if ($image_url) { echo '' . "\n"; echo '' . esc_url($image_url) . '' . "\n"; echo '' . esc_html($product->get_name()) . '' . "\n"; echo '' . "\n"; } } echo '' . "\n"; } // Pages $pages = get_posts(array( 'post_type' => 'page', 'post_status' => 'publish', 'numberposts' => -1 )); foreach ($pages as $page) { echo '' . "\n"; echo '' . esc_url(get_permalink($page->ID)) . '' . "\n"; echo '' . date('Y-m-d\TH:i:s+00:00', strtotime($page->post_modified)) . '' . "\n"; echo 'monthly' . "\n"; echo '0.6' . "\n"; echo '' . "\n"; } // Product categories $categories = get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => true )); foreach ($categories as $category) { echo '' . "\n"; echo '' . esc_url(get_term_link($category)) . '' . "\n"; echo '' . date('Y-m-d\TH:i:s+00:00') . '' . "\n"; echo 'weekly' . "\n"; echo '0.7' . "\n"; echo '' . "\n"; } echo '' . "\n"; exit; } } add_action('template_redirect', 'nordiccommerce_generate_sitemap'); /** * Add sitemap rewrite rule */ function nordiccommerce_sitemap_rewrite() { add_rewrite_rule('^sitemap\.xml$', 'index.php?sitemap=1', 'top'); } add_action('init', 'nordiccommerce_sitemap_rewrite'); /** * Add sitemap query var */ function nordiccommerce_sitemap_query_vars($vars) { $vars[] = 'sitemap'; return $vars; } add_filter('query_vars', 'nordiccommerce_sitemap_query_vars'); /** * Voice search optimization */ function nordiccommerce_voice_search_optimization() { // Add speakable content markers add_filter('the_content', function($content) { if (is_product()) { // Mark key product information as speakable $content = preg_replace( '/(]*>.*?<\/h[2-3]>)/i', '
$1
', $content ); // Mark feature lists as speakable $content = preg_replace( '/(]*class="[^"]*features[^"]*"[^>]*>.*?<\/ul>)/is', '
$1
', $content ); } return $content; }); } add_action('init', 'nordiccommerce_voice_search_optimization'); /** * Add microdata for better AI understanding */ function nordiccommerce_microdata_enhancement() { if (is_product()) { add_filter('woocommerce_single_product_summary', function() { echo ''; }, 5); } } add_action('init', 'nordiccommerce_microdata_enhancement'); EOF < /dev/null // Include WooCommerce enhancements require_once get_template_directory() . '/inc/woocommerce-functions.php'; // Include Stripe enhancements require_once get_template_directory() . '/inc/stripe-enhancements.php'; /** * Enhanced WooCommerce product display */ function nordiccommerce_product_enhancements() { // Add product view counter if (is_product()) { add_action('wp', function() { global $post; if ($post && $post->post_type === 'product') { $views = get_post_meta($post->ID, '_product_views', true); $views = $views ? intval($views) + 1 : 1; update_post_meta($post->ID, '_product_views', $views); } }); } // Enhanced product tabs add_filter('woocommerce_product_tabs', function($tabs) { // Add specifications tab $tabs['specifications'] = array( 'title' => 'Specifications', 'priority' => 15, 'callback' => 'nordiccommerce_specifications_tab_content' ); // Add shipping tab $tabs['shipping_info'] = array( 'title' => 'Shipping & Returns', 'priority' => 25, 'callback' => 'nordiccommerce_shipping_tab_content' ); return $tabs; }); } add_action('init', 'nordiccommerce_product_enhancements'); /** * Specifications tab content */ function nordiccommerce_specifications_tab_content() { global $product; echo '
'; // Product attributes $attributes = $product->get_attributes(); if (\!empty($attributes)) { echo ''; foreach ($attributes as $attribute) { if ($attribute->get_visible()) { echo ''; echo ''; echo ''; echo ''; } } echo '
' . wc_attribute_label($attribute->get_name()) . '' . $product->get_attribute($attribute->get_name()) . '
'; } // Additional specifications echo '

Product Details

'; echo ''; echo ''; echo ''; $dimensions = $product->get_dimensions(false); if (\!empty($dimensions['length']) || \!empty($dimensions['width']) || \!empty($dimensions['height'])) { echo ''; } echo ''; echo ''; echo '
SKU' . ($product->get_sku() ?: 'N/A') . '
Weight' . ($product->get_weight() ? $product->get_weight() . ' kg' : 'N/A') . '
Dimensions' . wc_format_dimensions($dimensions) . '
ConditionNew
Warranty1 Year Manufacturer Warranty
'; echo '
'; } /** * Shipping tab content */ function nordiccommerce_shipping_tab_content() { echo '
'; echo '

Shipping Information

'; echo '
    '; echo '
  • Free Shipping: On orders over 500 SEK
  • '; echo '
  • Standard Delivery: 2-4 business days
  • '; echo '
  • Express Delivery: 1-2 business days (additional cost)
  • '; echo '
  • International Shipping: Available to most countries
  • '; echo '
'; echo '

Returns & Exchanges

'; echo '
    '; echo '
  • Return Period: 30 days from delivery
  • '; echo '
  • Return Condition: Items must be unused and in original packaging
  • '; echo '
  • Return Shipping: Free returns within Sweden
  • '; echo '
  • Refund Processing: 3-5 business days after we receive your return
  • '; echo '
'; echo '

Customer Support

'; echo '

Need help with your order? Contact our customer support team:

'; echo '
    '; echo '
  • Email: support@stinkyfishchallenge.com
  • '; echo '
  • Phone: +46 (0)8 123 45 67
  • '; echo '
  • Hours: Monday-Friday 9:00-17:00 CET
  • '; echo '
'; echo '
'; } /** * Enhanced cart functionality */ function nordiccommerce_cart_enhancements() { // Add estimated delivery date to cart add_action('woocommerce_cart_totals_after_order_total', function() { $estimated_delivery = date('M j, Y', strtotime('+3 days')); echo ''; echo 'Estimated Delivery:'; echo '' . esc_html($estimated_delivery) . ''; echo ''; }); // Add cart recommendations add_action('woocommerce_cart_collaterals', function() { if (WC()->cart->is_empty()) return; // Get cart product categories $cart_categories = array(); foreach (WC()->cart->get_cart() as $cart_item) { $product_categories = get_the_terms($cart_item['product_id'], 'product_cat'); if ($product_categories) { foreach ($product_categories as $category) { $cart_categories[] = $category->term_id; } } } if (empty($cart_categories)) return; // Get recommended products $recommendations = wc_get_products(array( 'limit' => 4, 'status' => 'publish', 'category' => array_unique($cart_categories), 'exclude' => array_keys(WC()->cart->get_cart()) )); if (\!empty($recommendations)) { echo '
'; echo '

You might also like

'; echo ''; echo '
'; } }); } add_action('init', 'nordiccommerce_cart_enhancements'); /** * Advanced search functionality */ function nordiccommerce_advanced_search() { // Add AJAX search suggestions add_action('wp_ajax_product_search_suggestions', 'nordiccommerce_search_suggestions'); add_action('wp_ajax_nopriv_product_search_suggestions', 'nordiccommerce_search_suggestions'); } add_action('init', 'nordiccommerce_advanced_search'); function nordiccommerce_search_suggestions() { $term = sanitize_text_field($_GET['term']); if (strlen($term) < 2) { wp_die(); } $suggestions = array(); // Search products $products = wc_get_products(array( 'limit' => 5, 'status' => 'publish', 's' => $term )); foreach ($products as $product) { $suggestions[] = array( 'label' => $product->get_name(), 'value' => $product->get_name(), 'url' => $product->get_permalink(), 'image' => wp_get_attachment_image_url($product->get_image_id(), 'thumbnail'), 'price' => $product->get_price_html() ); } // Search categories $categories = get_terms(array( 'taxonomy' => 'product_cat', 'name__like' => $term, 'number' => 3 )); foreach ($categories as $category) { $suggestions[] = array( 'label' => $category->name . ' (Category)', 'value' => $category->name, 'url' => get_term_link($category), 'type' => 'category' ); } wp_send_json($suggestions); } /** * Customer account enhancements */ function nordiccommerce_account_enhancements() { // Add custom account dashboard widgets add_action('woocommerce_account_dashboard', function() { $current_user = wp_get_current_user(); $customer = new WC_Customer($current_user->ID); echo ''; }, 5); } add_action('init', 'nordiccommerce_account_enhancements'); EOF < /dev/null /** * Customizer Integration * Load customizer functionality and dynamic CSS generation */ require_once get_template_directory() . "/inc/customizer.php"; require_once get_template_directory() . "/inc/customizer-integration.php"; // Initialize customizer add_action("customize_register", "nordiccommerce_customize_register"); /** * AI Premium Features Integration * Load advanced AI-powered functionality */ require_once get_template_directory() . "/inc/ai-premium-features.php"; /** * AI Premium Features Customizer Integration */ add_action("customize_register", function($wp_customize) { // AI Premium Section $wp_customize->add_section("nordiccommerce_ai_premium", array( "title" => "AI Premium Features", "priority" => 46, "description" => "Advanced AI-powered features for maximum conversions" )); // AI Product Recommendations $wp_customize->add_setting("nordiccommerce_ai_recommendations", array( "default" => true, "sanitize_callback" => "rest_sanitize_boolean" )); $wp_customize->add_control("nordiccommerce_ai_recommendations", array( "label" => "AI Product Recommendations", "section" => "nordiccommerce_ai_premium", "type" => "checkbox", "description" => "Show AI-powered product recommendations based on user behavior" )); // Smart Search $wp_customize->add_setting("nordiccommerce_ai_smart_search", array( "default" => true, "sanitize_callback" => "rest_sanitize_boolean" )); $wp_customize->add_control("nordiccommerce_ai_smart_search", array( "label" => "AI Smart Search", "section" => "nordiccommerce_ai_premium", "type" => "checkbox", "description" => "Enable intelligent search suggestions and voice search" )); // Personalization $wp_customize->add_setting("nordiccommerce_ai_personalization", array( "default" => true, "sanitize_callback" => "rest_sanitize_boolean" )); $wp_customize->add_control("nordiccommerce_ai_personalization", array( "label" => "Content Personalization", "section" => "nordiccommerce_ai_premium", "type" => "checkbox", "description" => "Personalize content based on user behavior and preferences" )); // Smart Notifications $wp_customize->add_setting("nordiccommerce_ai_notifications", array( "default" => true, "sanitize_callback" => "rest_sanitize_boolean" )); $wp_customize->add_control("nordiccommerce_ai_notifications", array( "label" => "Smart Notifications", "section" => "nordiccommerce_ai_premium", "type" => "checkbox", "description" => "Show intelligent notifications for cart abandonment and offers" )); });