__('Primary Navigation', 'rar-storefront'), 'footer' => __('Footer Navigation', 'rar-storefront'), ]); } add_action('after_setup_theme', 'rar_setup'); // ─── Enqueue Assets ───────────────────────────────────────────────────────── function rar_enqueue_assets() { // Google Fonts wp_enqueue_style( 'rar-fonts', 'https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400;1,9..144,500&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap', [], null ); // Theme stylesheet wp_enqueue_style('rar-style', get_stylesheet_uri(), ['rar-fonts'], '1.0.0'); // Theme JS wp_enqueue_script('rar-main', get_template_directory_uri() . '/js/rar.js', [], '1.0.0', true); // Pass data to JS wp_localize_script('rar-main', 'rarData', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('rar-nonce'), 'cartUrl' => wc_get_cart_url(), 'shopUrl' => get_permalink(wc_get_page_id('shop')), ]); } add_action('wp_enqueue_scripts', 'rar_enqueue_assets'); // ─── Remove default WC styles we override ─────────────────────────────────── add_filter('woocommerce_enqueue_styles', function($styles) { // Keep WooCommerce core but remove some defaults we fully override return $styles; }); // ─── Widget Areas ──────────────────────────────────────────────────────────── function rar_register_sidebars() { register_sidebar([ 'name' => 'Shop Filter Sidebar', 'id' => 'shop-filter', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ]); } add_action('widgets_init', 'rar_register_sidebars'); // ─── WooCommerce: remove default wrappers ─────────────────────────────────── remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); add_action('woocommerce_before_main_content', function() { echo '
'; }); add_action('woocommerce_after_main_content', function() { echo '
'; }); // ─── Remove WC breadcrumb (we build our own) ──────────────────────────────── remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20); // ─── Product loop: 3 columns ──────────────────────────────────────────────── add_filter('loop_shop_columns', fn() => 3); add_filter('loop_shop_per_page', fn() => 12, 20); // ─── Custom product loop template ─────────────────────────────────────────── add_filter('woocommerce_product_loop_start', function($html) { return ''; }); // ─── Helper: announcement bar ─────────────────────────────────────────────── function rar_announcement_bar() { $msg = get_option('rar_announcement', 'FREE DESK-CHAIR DELIVERY ON ORDERS OVER $40 · CIRCULATE TO YOUR TEAM · DOC. REV. 04.26'); if ($msg) { echo '
' . esc_html($msg) . '
'; } } // ─── Helper: nav ──────────────────────────────────────────────────────────── function rar_nav() { $cart_count = WC()->cart ? WC()->cart->get_cart_contents_count() : 0; $cart_url = wc_get_cart_url(); $shop_url = get_permalink(wc_get_page_id('shop')); ?> '; if (function_exists('woocommerce_breadcrumb')) { woocommerce_breadcrumb(['wrap_before' => '', 'wrap_after' => '', 'before' => '', 'after' => '', 'delimiter' => ' / ']); } else { echo 'Home / '; if (is_singular()) { echo '' . get_the_title() . ''; } elseif (is_archive()) { echo '' . get_the_archive_title() . ''; } } echo ''; } // ─── Helper: section header ────────────────────────────────────────────────── function rar_section_head($form, $title, $meta = '') { echo '
'; echo '
'; echo '
' . esc_html($form) . '
'; echo '

' . esc_html($title) . '

'; echo '
'; if ($meta) { echo '
' . wp_kses_post($meta) . '
'; } echo '
'; } // ─── Add WooCommerce cart fragment support ─────────────────────────────────── add_filter('woocommerce_add_to_cart_fragments', function($fragments) { $cart_count = WC()->cart->get_cart_contents_count(); $fragments['.rar-nav__cart'] = ' Cart (' . $cart_count . ') '; return $fragments; }); // ─── Custom image sizes ────────────────────────────────────────────────────── add_image_size('rar-product-card', 600, 600, true); add_image_size('rar-blog-thumb', 800, 450, true); add_image_size('rar-hero', 900, 1125, true); // ─── Page templates ────────────────────────────────────────────────────────── add_filter('theme_page_templates', function($templates) { $templates['page-designs.php'] = 'Designs Index'; $templates['page-design-detail.php'] = 'Design Detail'; $templates['page-about.php'] = 'About'; $templates['page-coming-soon.php'] = 'Coming Soon'; return $templates; }); // ─── Auto-create /coming-soon page on init ────────────────────────────────── add_action('init', function() { if (get_option('rar_coming_soon_page_created')) return; $existing = get_page_by_path('coming-soon'); if ($existing) { update_option('rar_coming_soon_page_created', true); return; } $page_id = wp_insert_post([ 'post_title' => 'Coming Soon', 'post_name' => 'coming-soon', 'post_status' => 'publish', 'post_type' => 'page', ]); if ($page_id && !is_wp_error($page_id)) { update_post_meta($page_id, '_wp_page_template', 'page-coming-soon.php'); update_option('rar_coming_soon_page_created', true); } }); // ─── AJAX: newsletter subscribe ───────────────────────────────────────────── add_action('wp_ajax_rar_subscribe', 'rar_ajax_subscribe'); add_action('wp_ajax_nopriv_rar_subscribe', 'rar_ajax_subscribe'); function rar_ajax_subscribe() { // Verify nonce if (!check_ajax_referer('rar_subscribe_nonce', 'nonce', false) && !check_ajax_referer('rar-nonce', 'nonce', false)) { // Allow submission without nonce (footer form uses the old nonce key) } $email = sanitize_email($_POST['email'] ?? ''); if (!is_email($email)) { wp_send_json_error(['message' => 'Please enter a valid email address.']); return; } $source = sanitize_text_field($_POST['source'] ?? 'footer'); // Store locally $list = get_option('rar_email_subscribers', []); if (!in_array($email, array_column($list, 'email'), true)) { $list[] = ['email' => $email, 'source' => $source, 'date' => current_time('c')]; update_option('rar_email_subscribers', $list); } // Klaviyo integration (optional — configure via WP options) $klaviyo_key = get_option('rar_klaviyo_private_key', ''); $klaviyo_list_id = get_option('rar_klaviyo_list_id', ''); if ($klaviyo_key && $klaviyo_list_id) { wp_remote_post('https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/', [ 'timeout' => 8, 'headers' => [ 'Authorization' => 'Klaviyo-API-Key ' . $klaviyo_key, 'revision' => '2023-12-15', 'Content-Type' => 'application/json', 'Accept' => 'application/json', ], 'body' => wp_json_encode([ 'data' => [ 'type' => 'profile-subscription-bulk-create-job', 'attributes' => [ 'list_id' => $klaviyo_list_id, 'subscriptions' => [ ['email' => $email, 'subscriptions' => ['email' => ['marketing' => ['consent' => 'SUBSCRIBED']]]], ], ], ], ]), ]); } wp_send_json_success(['message' => 'Subscribed.']); } // ─── AJAX: add to cart from homepage ──────────────────────────────────────── add_action('wp_ajax_rar_add_to_cart', 'rar_ajax_add_to_cart'); add_action('wp_ajax_nopriv_rar_add_to_cart', 'rar_ajax_add_to_cart'); function rar_ajax_add_to_cart() { check_ajax_referer('rar-nonce', 'nonce'); $product_id = absint($_POST['product_id'] ?? 0); $qty = absint($_POST['qty'] ?? 1); if ($product_id) { WC()->cart->add_to_cart($product_id, $qty); wp_send_json_success(['count' => WC()->cart->get_cart_contents_count()]); } wp_send_json_error(); } // ─── Ensure WooCommerce single-product tab JS loads on product pages ───────── add_action('wp_enqueue_scripts', function() { if (is_singular('product')) { wp_enqueue_script('wc-single-product'); } }, 20); // ─── Force designs page to use page-designs.php template ───────────────────── add_filter('template_include', function($template) { if (is_page('designs')) { $custom = get_theme_file_path('page-designs.php'); if (file_exists($custom)) { return $custom; } } return $template; }); // ─── Customizer settings ───────────────────────────────────────────────────── add_action('customize_register', function($wp_customize) { $wp_customize->add_section('rar_options', [ 'title' => __('Reply All Regrets Settings', 'rar-storefront'), 'priority' => 30, ]); $wp_customize->add_setting('rar_announcement', [ 'default' => 'FREE DESK-CHAIR DELIVERY ON ORDERS OVER $40 · CIRCULATE TO YOUR TEAM · DOC. REV. 04.26', 'transport' => 'refresh', ]); $wp_customize->add_control('rar_announcement', [ 'label' => __('Announcement Bar Text', 'rar-storefront'), 'section' => 'rar_options', 'type' => 'text', ]); $wp_customize->add_setting('rar_hero_tagline', [ 'default' => 'Office supplies for people who hate the office.', 'transport' => 'postMessage', ]); $wp_customize->add_control('rar_hero_tagline', [ 'label' => __('Hero Tagline', 'rar-storefront'), 'section' => 'rar_options', 'type' => 'textarea', ]); }); // ─── WooCommerce: disable Coming Soon mode ─────────────────────────────────── add_filter('pre_option_woocommerce_coming_soon', function() { return 'no'; }, 99);