functions.php 48.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
<?php
/*
 * Created on : Mar 4, 2016, 3:52:05 PM
 * Author: Tran Trong Thang
 * Email: trantrongthang1207@gmail.com
 * Skype: trantrongthang1207
 */

function theme_enqueue_styles() {
    $parent_style = 'parent-style';
    $current_path = $_SERVER["REQUEST_URI"];
    $directory_uri = get_stylesheet_directory_uri();
    $childThemeJs = $directory_uri . '/assets/js/';
    $fgcJs = $directory_uri . '/assets/js/fgc/';
    wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css');
    wp_enqueue_style('child-style', $directory_uri . '/style.css', array($parent_style));
    $isOtherPage = true;
    if (!strpos($current_path, 'login-page')) {
        wp_enqueue_style('child-style-custom-free', $directory_uri . '/assets/css/free.css', array($parent_style));
        wp_enqueue_script('child-script-bootstrap', $childThemeJs . 'bootstrap.min.js', array('jquery'));
        wp_enqueue_script('child-script-jquery.mask', $childThemeJs . 'jquery.mask.js', array('jquery'));
        wp_enqueue_script('child-script', $fgcJs . 'fgcscript.js', array('jquery'));
    }

//    if (strpos($current_path, 'get-started') || strpos($current_path, 'downgrade') || strpos($current_path, 'upgrade') || strpos($current_path, 'single-purchase')) {
    wp_enqueue_script('child-script-slider', $fgcJs . 'fgcslider.js', array('jquery'));
//    }

    wp_enqueue_script('child-script-mobile', $childThemeJs . 'jquery.mobile.custom.js', array('jquery'));
    wp_enqueue_script('child-script-cookie', $childThemeJs . 'jquery.cookie.js', array('jquery'));

    wp_enqueue_style('child-style-font-awesome-min', $directory_uri . '/assets/css/font-awesome.min.css', array($parent_style));
    wp_enqueue_style('child-style-bootstrap', $directory_uri . '/assets/css/bootstrap.css', array($parent_style));
    wp_enqueue_style('child-style-fonts', $directory_uri . '/assets/css/fonts.css', array($parent_style));

    if (strpos($current_path, 'login-page')) {
        wp_enqueue_style('child-style-login-page', $directory_uri . '/assets/css/login-page.css', array($parent_style));
        wp_enqueue_script('child-script-login-page', $fgcJs . 'login-page.js', array('jquery'));
        $isOtherPage = false;
    }
    wp_enqueue_script('child-script-myaccount', $fgcJs . 'fgc.myaccount.js', array('jquery'));
    wp_enqueue_script('child-script-payment', $childThemeJs . 'jquery.payment.js', array('jquery'));
    wp_enqueue_script('child-script-checkout', $fgcJs . 'fgc.checkout.js', array('jquery'));
    if (strpos($current_path, 'my-account') || strpos($current_path, 'checkout')) {
        $isOtherPage = false;
    }
    if (strpos($current_path, 'our-news')) {
        wp_enqueue_script('child-script-masonry', $childThemeJs . 'masonry.pkgd.min.js', array('jquery'));
        wp_enqueue_script('child-script-load-posts', $childThemeJs . 'load-more-post.js', array('jquery'));
        wp_enqueue_script('child-script-imagesloaded', $childThemeJs . 'imagesloaded.pkgd.min.js', array('jquery'));
    }
    if (strpos($current_path, 'deadpan-guy')) {
        wp_enqueue_script('child-script-min-js', $childThemeJs . 'plugins.js', array('jquery'));
        wp_enqueue_script('child-script-arctext', $childThemeJs . 'circletype.min.js', array('jquery'));
        wp_enqueue_script('child-script-deadpan-guy', $fgcJs . 'fgc.deadpanguy.js', array('jquery'));
        $isOtherPage = false;
    }
    if (strpos($current_path, 'take-month-off')) {
        wp_enqueue_script('child-script-take-month-off', $fgcJs . 'fgc.takemonthoff.js', array('jquery'));
        $isOtherPage = false;
    }
    if ($isOtherPage) {
        wp_enqueue_script('child-script-otherpage', $fgcJs . 'fgc.otherpages.js', array('jquery'));
    }
    if (strpos($current_path, 'checkout/order-received')) {
        wp_dequeue_script('storefront-sticky-payment');
    }
    if (is_page_template('christmas-landing.php')) {
        wp_enqueue_style('child-style-christmas-page', $directory_uri . '/assets/css/christmas_landing-page.css', array($parent_style));
    }
}

add_action('wp_enqueue_scripts', 'theme_enqueue_styles');

function theme_enqueue_styles_responsive() {
    $parent_style = 'parent-style';
    wp_enqueue_style('child-style-custom', get_stylesheet_directory_uri() . '/assets/css/custom.css', array($parent_style));
    wp_enqueue_style('child-style-responsive', get_stylesheet_directory_uri() . '/assets/css/responsive.css', array($parent_style));
}

add_action('wp_enqueue_scripts', 'theme_enqueue_styles_responsive', 99);

add_action('init', 'tv_remove_storefront_primary_navigation', 50);

function tv_remove_storefront_primary_navigation() {
    remove_action('storefront_header', 'storefront_primary_navigation', 50);
    add_action('storefront_header', 'custom_storefront_primary_navigation', 50);
}

function custom_storefront_primary_navigation() {
    ?>
    <div class="tvclearfix">
        &nbsp;
    </div>
    <nav id="site-navigation" class="main-navigation" role="navigation" aria-label="
         <?php esc_html_e('Primary Navigation', 'storefront'); ?>">
        <button class="menu-toggle" aria-controls="primary-navigation" aria-expanded="false"><?php echo esc_attr(apply_filters('storefront_menu_toggle_text', __('Navigation', 'storefront'))); ?></button>
        <?php
        wp_nav_menu(
                array(
                    'theme_location' => 'primary',
                    'container_class' => 'primary-navigation',
                )
        );
        ?>
    </nav>
    <!-- #site-navigation -->
    <?php
}

add_action('init', 'tv_remove_footer_credit', 20);

function tv_remove_footer_credit() {
    remove_action('storefront_footer', 'storefront_credit', 20);
    add_action('storefront_footer', 'custom_storefront_credit', 20);
}

function custom_storefront_credit() {
    ?>
    <div class="clearfix">
    </div>
    <div class="site-info">
        <div class="pull-right">
            <div>
                &copy;
                <?php echo get_the_date('Y') . ' ' . get_bloginfo('name'); ?>
                <span>Energy Drink. All Rights Reserved</span>
            </div>
            <div>
                <a href="/legal-terms">Legal Terms</a>
            </div>
        </div>
    </div>
    <!-- .site-info -->
    <?php
}

function register_footer_menu() {
    register_nav_menu('footer-menu', __('Footer Menu'));
}

add_action('init', 'register_footer_menu');
add_action('init', 'tv_remove_storefront_secondary_navigation', 30);

function tv_remove_storefront_secondary_navigation() {
    remove_action('storefront_header', 'storefront_secondary_navigation', 30);
    add_action('storefront_header', 'custom_storefront_secondary_navigation', 30);
}

function custom_storefront_secondary_navigation() {
    global $woocommerce;
    ?>
    <nav aria-label="Secondary Navigation" role="navigation" class="secondary-navigation">
        <a class="menu-toggle-user" href="">&nbsp;</a>
        <div class="menu-top-nav-links-container
             <?php echo is_user_logged_in() ? 'islogin' : '' ?>">
            <ul class="menu" id="menu-top-nav-links">
                <?php
                if (is_user_logged_in()) {
                    ?>
                    <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-14" id="menu-item-14">
                        <span class="icon_user">&nbsp;</span>
                        <a href="
                           <?php echo get_site_url(); ?>/my-account/"><span>My account</span></a>
                    </li>
                    <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-13 menu-item-logout" id="menu-item-13">
                        <!--<a href="<?php echo wp_logout_url(home_url()); ?>">Logout</a>-->
                        <!--<a href="<?php echo wp_loginout(home_url()); ?>">Logout</a>-->
                        <?php // echo wp_loginout(home_url());            ?>
                        <a href="<?php echo wp_logout_url(home_url()) ?>" title="Logout">Logout</a>
                    </li>
                    <?php
                } else {
                    ?>
                    <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-14" id="menu-item-14">
                        <a id="show_login"  class="show_login" href="
                           <?php echo get_site_url(); ?>/login-page/"><span>Register</span></a>
                    </li>
                    <li class="line-break"><span>&nbsp;</span></li>
                    <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-13" id="menu-item-13">
                        <a id="show_login"  class="show_login" href="
                           <?php echo get_site_url(); ?>/login-page/"><span>Login</span></a>
                    </li>

                <?php }
                ?>
            </ul>
            <a href="<?php echo $woocommerce->cart->get_checkout_url(); ?>" id="show_signup"></a>
        </div>
    </nav>
    <?php
}

remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20);
add_action('woocommerce_checkout_before_billing', 'woocommerce_checkout_payment', 20);
add_action('init', 'tv_override_default_address_fields', 30);
// Hook in
add_filter('woocommerce_default_address_fields', 'tv_override_default_address_fields');

// Our hooked in function - $address_fields is passed via the filter!
function tv_override_default_address_fields($address_fields) {
    $fields = array(
        'first_name' => array(
            'label' => __('Name', 'woocommerce'),
            'placeholder' => _x('Name', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-wide'),
        ),
        'last_name' => array(
            'label' => __('Surname', 'woocommerce'),
            'placeholder' => _x('Surname', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-wide'),
            'clear' => true
        ),
        'address_1' => array(
            'label' => __('Address Line 1', 'woocommerce'),
            'placeholder' => _x('Address Line 1', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-wide', 'address-field')
        ),
        'address_2' => array(
            'placeholder' => _x('Address Line 2', 'placeholder', 'woocommerce'),
            'class' => array('form-row-wide', 'address-field'),
            'required' => false
        ),
        'city' => array(
            'label' => __('City', 'woocommerce'),
            'placeholder' => _x('City', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-wide', 'address-field')
        ),
        'state' => array(
            'type' => 'state',
            'label' => __('State / County', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-first tvstate', 'address-field'),
            'validate' => array('state')
        ),
        'postcode' => array(
            'label' => __('Postcode / ZIP', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-last', 'address-field'),
            'placeholder' => _x('Postcode', 'placeholder', 'woocommerce'),
            'clear' => true,
            'validate' => array('postcode')
        ),
        'company' => array(
            'label' => __('Company Name', 'woocommerce'),
            'class' => array('form-row-wide hide'),
        ),
        'country' => array(
            'type' => 'country',
            'label' => __('Country', 'woocommerce'),
            'required' => true,
            'class' => array('form-row-wide', 'address-field', 'update_totals_on_change'),
        ),
    );
    return $fields;
}

add_action('init', 'tv_override_billing_fields', 30);
add_filter('woocommerce_billing_fields', 'tv_override_billing_fields');

function tv_override_billing_fields($fields) {
    $fields['billing_phone']['placeholder'] = _x('Phone', 'placeholder', 'woocommerce');
    $fields['billing_email']['placeholder'] = _x('Email', 'placeholder', 'woocommerce');
    return $fields;
}

add_filter('woocommerce_checkout_fields', 'tv_override_checkout_fields');

function tv_override_checkout_fields($fields) {
    $fields['order']['order_comments']['placeholder'] = _x('Enter details here...', 'placeholder', 'woocommerce');
    return $fields;
}

// Display 40 products per page. Goes in functions.php
add_filter('loop_shop_per_page', create_function('$cols', 'return 40;'), 20);
// Remove product images from the shop loop
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);

// add_filter('add_to_cart_redirect', 'redirect_to_checkout');
// function redirect_to_checkout() {
//     global $woocommerce;
//     $checkout_url = $woocommerce->cart->get_checkout_url();
//     return $checkout_url;
// }
// wp_dequeue_script('wc-add-to-cart');
// wp_enqueue_script('wc-add-to-cart', get_stylesheet_directory_uri() . '/assets/js/add-to-cart.js', array('jquery'), false, true);


function fgc_add_current_plan($content) {
    $request_uri = $_SERVER["REQUEST_URI"];
    if (strpos($request_uri, '/upgrade') || strpos($request_uri, '/downgrade')) {
        $user_ID = get_current_user_id();
        $subscription_result = FGC_ActiveCampaign::get_info_of_active_or_onhold_subscription($user_ID);
        if ($subscription_result['has_subscription']) {
            if (strpos($request_uri, '/upgrade') && $subscription_result['current_drink'] == 600) {
                echo '<META HTTP-EQUIV="Refresh" Content="0; URL=' . get_site_url() . '/my-account' . '">';
                exit();
            }
            if (strpos($request_uri, '/downgrade') && $subscription_result['current_drink'] == 12) {
                echo '<META HTTP-EQUIV="Refresh" Content="0; URL=' . get_site_url() . '/my-account' . '">';
                exit();
            }
        } else {
            echo '<META HTTP-EQUIV="Refresh" Content="0; URL=' . get_site_url() . '/get-started' . '">';
            exit();
        }
    }
    return $content;
}

add_filter('wp_head', 'fgc_add_current_plan');
// Remove order details on Order Confirm page.
remove_action('woocommerce_thankyou', 'woocommerce_order_details_table', 10);
if (!function_exists('wc_dropdown_variation_attribute_options')) {

    /**
     * Output a list of variation attributes for use in the cart forms.
     *
     * @param array $args
     * @since 2.4.0
     */
    function wc_dropdown_variation_attribute_options($args = array()) {
        $args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array(
            'options' => false,
            'attribute' => false,
            'product' => false,
            'selected' => false,
            'name' => '',
            'id' => '',
            'class' => '',
            'show_option_none' => __('Choose an option', 'woocommerce')
        ));
        $options = $args['options'];
        $product = $args['product'];
        $attribute = $args['attribute'];
        $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
        $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
        $class = $args['class'];
        if (empty($options) && !empty($product) && !empty($attribute)) {
            $attributes = $product->get_variation_attributes();
            $options = $attributes[$attribute];
        }
        $html = '<select id="' . esc_attr($id) . '" class="' . esc_attr($class) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
        if ($args['show_option_none']) {
            $html .= '<option value="">' . esc_html($args['show_option_none']) . '</option>';
        }
        if (!empty($options)) {
            if ($product && taxonomy_exists($attribute)) {
                // Get terms if this is a taxonomy - ordered. We need the names too.
                $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
                foreach ($terms as $term) {
                    if (in_array($term->slug, $options)) {
                        $html .= '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $term->name)) . '</option>';
                    }
                }
            } else {
                foreach ($options as $option) {
                    // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                    $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);
                    $html .= '<option class="option_value" value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
                }
            }
        }
        $html .= '</select>';
        echo apply_filters('woocommerce_dropdown_variation_attribute_options_html', $html, $args);
    }

}

//Change subscription
function fgc_subscription_switch_handler() {
    global $post;
    // If the current user doesn't own the subscription, remove the query arg from the URL
    if (isset($_POST['switch-subscription'])) {
        $subscription = wcs_get_subscription($_POST['switch-subscription']);
        // Visiting a switch link for someone elses subscription or if the switch link doesn't contain a valid nonce
        if (!is_object($subscription) || !current_user_can('switch_shop_subscription', $subscription->id) || empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_switch_request') || 'no' === get_option(WC_Subscriptions_Admin::$option_prefix . '_allow_switching', 'no')) {
            wp_redirect(remove_query_arg(array('switch-subscription', 'auto-switch', 'item', '_wcsnonce')));
            exit();
        } else {
            if (isset($_POST['auto-switch'])) {
                $switch_message = __('You have a subscription to this product. Choosing a new subscription will replace your existing subscription.', 'woocommerce-subscriptions');
            } else {
                $switch_message = __('Choose a new subscription.', 'woocommerce-subscriptions');
            }
            WC_Subscriptions::add_notice($switch_message, 'notice');
        }
    } elseif (( is_cart() || is_checkout() ) && !is_order_received_page() && false !== ( $switch_items = WC_Subscriptions_Switcher::cart_contains_switches() )) {
        $removed_item_count = 0;
        // foreach ($switch_items as $cart_item_key => $switch_item) {
        //     $subscription = wcs_get_subscription($switch_item['subscription_id']);
        //     if (!is_object($subscription) || !current_user_can('switch_shop_subscription', $subscription->id) || !wcs_is_product_switchable_type(WC()->cart->cart_contents[$cart_item_key]['data'])) {
        //         WC()->cart->remove_cart_item($cart_item_key);
        //         $removed_item_count++;
        //     }
        // }
        if ($removed_item_count > 0) {
            WC_Subscriptions::add_notice(_n('Your cart contained an invalid subscription switch request. It has been removed.', 'Your cart contained invalid subscription switch requests. They have been removed.', $removed_item_count, 'woocommerce-subscriptions'), 'error');
            wp_redirect(WC()->cart->get_cart_url());
            exit();
        }
    } elseif (is_product() && $product = wc_get_product($post)) { // Automatically initiate the switch process for limited variable subscriptions
        if (wcs_is_product_switchable_type($product) && 'no' != $product->limit_subscriptions) {
            // Check if the user has an active subscription for this product, and if so, initiate the switch process
            $subscriptions = wcs_get_users_subscriptions();
            $child_ids = $product->get_children();
            foreach ($subscriptions as $subscription) {
                // If we're on a grouped product's page, we need to check if the subscription has a child of this grouped product that needs to be switched
                $subscription_product_id = false;
                if ($product->is_type('grouped')) {
                    foreach ($child_ids as $child_id) {
                        if ($subscription->has_product($child_id)) {
                            $subscription_product_id = $child_id;
                            break;
                        }
                    }
                }
                if ($subscription->has_product($product->id) || $subscription_product_id) {
                    // For grouped products, we need to check the child products limitations, not the grouped product's (which will have no limitation)
                    if ($subscription_product_id) {
                        $child_product = wc_get_product($subscription_product_id);
                        $limitation = $child_product->limit_subscriptions;
                    } else {
                        $limitation = $product->limit_subscriptions;
                    }
                    // If the product is limited
                    if ('any' == $limitation || $subscription->has_status($limitation) || ( 'active' == $limitation && $subscription->has_status('on-hold') )) {
                        $subscribed_notice = __('You have already subscribed to this product and it is limited to one per customer. You can not purchase the product again.', 'woocommerce-subscriptions');
                        // If switching is enabled for this product type, initiate the auto-switch process
                        if (wcs_is_product_switchable_type($product)) {
                            // Don't initiate auto-switching when the subscription requires payment
                            if ($subscription->needs_payment()) {
                                $last_order = $subscription->get_last_order('all');
                                if ($last_order->needs_payment()) {
                                    // translators: 1$: is the "You have already subscribed to this product" notice, 2$-4$: opening/closing link tags, 3$: an order number
                                    $subscribed_notice = sprintf(__('%1$s Complete payment on %2$sOrder %3$s%4$s to be able to change your subscription.', 'woocommerce-subscriptions'), $subscribed_notice, sprintf('<a href="%s">', $last_order->get_checkout_payment_url()), $last_order->get_order_number(), '</a>');
                                }
                                WC_Subscriptions::add_notice($subscribed_notice, 'notice');
                                break;
                            } else {
                                $product_id = ( $subscription_product_id ) ? $subscription_product_id : $product->id;
                                // Get the matching item
                                foreach ($subscription->get_items() as $line_item_id => $line_item) {
                                    if ($line_item['product_id'] == $product_id || $line_item['variation_id'] == $product_id) {
                                        $item_id = $line_item_id;
                                        $item = $line_item;
                                        break;
                                    }
                                }
                                wp_redirect(add_query_arg('auto-switch', 'true', WC_Subscriptions_Switcher::get_switch_url($item_id, $item, $subscription)));
                                exit;
                            }
                        } else {
                            WC_Subscriptions::add_notice($subscribed_notice, 'notice');
                            break;
                        }
                    }
                }
            }
        }
    }
}

remove_filter('template_redirect', 'WC_Subscriptions_Switcher::subscription_switch_handler', 100);
add_filter('template_redirect', 'fgc_subscription_switch_handler', 10);

function fgc_add_switch_query_arg_grouped($permalink) {
    if (isset($_POST['switch-subscription'])) {
        $permalink = WC_Subscriptions_Switcher::add_switch_query_args($_POST['switch-subscription'], $_POST['item'], $permalink);
    }
    return $permalink;
}

add_filter('woocommerce_grouped_product_list_link', 'fgc_add_switch_query_arg_grouped', 20);

function fgc_add_switch_query_arg_post_link($permalink, $post) {
    if (!isset($_POST['switch-subscription']) || !is_main_query() || !is_product() || 'product' !== $post->post_type) {
        return $permalink;
    }
    $product = wc_get_product($post);
    if (!$product->is_type('subscription')) {
        return $permalink;
    }
    return WC_Subscriptions_Switcher::add_switch_query_args($_POST['switch-subscription'], $_POST['item'], $permalink);
}

add_filter('post_type_link', 'fgc_add_switch_query_arg_post_link', 20, 3);

function fgc_validate_switch_request($is_valid, $product_id, $quantity, $variation_id = '') {
    $error_message = '';
    try {
        if (!isset($_POST['switch-subscription'])) {
            return $is_valid;
        }
        if (empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_switch_request')) {
            return false;
        }
        $subscription = wcs_get_subscription($_POST['switch-subscription']);
        $item_id = absint($_POST['item']);
        $item = wcs_get_order_item($item_id, $subscription);
        // Check if the chosen variation's attributes are different to the existing subscription's attributes (to support switching between a "catch all" variation)
        if (empty($item)) {
            throw new Exception(__('We can not find your old subscription item.', 'woocommerce-subscriptions'));
        } else {
            $identical_attributes = true;
            foreach ($_POST as $key => $value) {
                if (false !== strpos($key, 'attribute_') && !empty($item[str_replace('attribute_', '', $key)]) && $item[str_replace('attribute_', '', $key)] != $value) {
                    $identical_attributes = false;
                    break;
                }
            }
            if ($product_id == $item['product_id'] && ( empty($variation_id) || ( $variation_id == $item['variation_id'] && true == $identical_attributes ) ) && $quantity == $item['qty']) {
                throw new Exception(__('You can not switch to the same subscription.', 'woocommerce-subscriptions'));
            }
            // Also remove any existing items in the cart for switching this item (but don't make the switch invalid)
            if ($is_valid) {
                $existing_switch_items = WC_Subscriptions_Switcher::cart_contains_switches();
                if (false !== $existing_switch_items) {
                    foreach ($existing_switch_items as $cart_item_key => $switch_item) {
                        if ($switch_item['item_id'] == $item_id) {
                            WC()->cart->remove_cart_item($cart_item_key);
                        }
                    }
                }
            }
        }
    } catch (Exception $e) {
        $error_message = $e->getMessage();
    }
    $error_message = apply_filters('woocommerce_subscriptions_switch_error_message', $error_message, $product_id, $quantity, $variation_id, $subscription, $item);
    if (!empty($error_message)) {
        wc_add_notice($error_message, 'error');
        $is_valid = false;
    }
    return apply_filters('woocommerce_subscriptions_is_switch_valid', $is_valid, $product_id, $quantity, $variation_id, $subscription, $item);
}

add_filter('woocommerce_add_to_cart_validation', 'fgc_validate_switch_request', 20, 5);

function fgc_set_switch_details_in_cart($cart_item_data, $product_id, $variation_id) {
    try {
        if (!isset($_POST['switch-subscription'])) {
            return $cart_item_data;
        }
        $subscription = wcs_get_subscription($_POST['switch-subscription']);
        // Requesting a switch for someone elses subscription
        if (!current_user_can('switch_shop_subscription', $subscription->id)) {
            WC_Subscriptions::add_notice(__('You can not switch this subscription. It appears you do not own the subscription.', 'woocommerce-subscriptions'), 'error');
            WC()->cart->empty_cart(true);
            wp_redirect(get_permalink($subscription['product_id']));
            exit();
        }
        $item = wcs_get_order_item(absint($_POST['item']), $subscription);
        // Else it's a valid switch
        $product = wc_get_product($item['product_id']);
        $child_products = ( 0 !== $product->post->post_parent ) ? wc_get_product($product->post->post_parent)->get_children() : array();
        if ($product_id != $item['product_id'] && !in_array($item['product_id'], $child_products)) {
            return $cart_item_data;
        }
        $next_payment_timestamp = $subscription->get_time('next_payment');
        // If there are no more payments due on the subscription, because we're in the last billing period, we need to use the subscription's expiration date, not next payment date
        if (false == $next_payment_timestamp) {
            $next_payment_timestamp = $subscription->get_time('end');
        }
        $cart_item_data['subscription_switch'] = array(
            'subscription_id' => $subscription->id,
            'item_id' => absint($_POST['item']),
            'next_payment_timestamp' => $next_payment_timestamp,
            'upgraded_or_downgraded' => '',
        );
        return $cart_item_data;
    } catch (Exception $e) {
        WC_Subscriptions::add_notice(__('There was an error locating the switch details.', 'woocommerce-subscriptions'), 'error');
        WC()->cart->empty_cart(true);
        wp_redirect(get_permalink(wc_get_page_id('cart')));
        exit();
    }
}

add_filter('woocommerce_add_cart_item_data', 'fgc_set_switch_details_in_cart', 20, 5);

function fgc_customise_product_string_inclusions($inclusions, $product) {
    if (isset($_POST['switch-subscription']) || WC_Subscriptions_Switcher::cart_contains_switch_for_product($product)) {
        $inclusions['trial_length'] = false;
        $apportion_length = get_option(WC_Subscriptions_Admin::$option_prefix . '_apportion_length', 'no');
        $apportion_sign_up_fee = get_option(WC_Subscriptions_Admin::$option_prefix . '_apportion_sign_up_fee', 'no');
        if ('yes' == $apportion_length || ( 'virtual' == $apportion_length && $product->is_virtual() )) {
            $inclusions['subscription_length'] = false;
        }
        if ('no' === $apportion_sign_up_fee) {
            $inclusions['sign_up_fee'] = false;
        }
    }
    return $inclusions;
}

add_filter('woocommerce_subscriptions_product_price_string_inclusions', 'fgc_customise_product_string_inclusions', 20, 3);

function fgc_is_purchasable($is_purchasable, $product) {
    if (false === $is_purchasable && wcs_is_product_switchable_type($product) && WC_Subscriptions_Product::is_subscription($product->id) && 'no' != $product->limit_subscriptions && is_user_logged_in() && wcs_user_has_subscription(0, $product->id, $product->limit_subscriptions)) {
        // Adding to cart from the product page
        if (isset($_POST['switch-subscription'])) {
            $is_purchasable = true;
            // Validating when restring cart from session
        } elseif (WC_Subscriptions_Switcher::cart_contains_switches()) {
            $is_purchasable = true;
            // Restoring cart from session, so need to check the cart in the session (self::cart_contains_subscription_switch() only checks the cart)
        } elseif (isset(WC()->session->cart)) {
            foreach (WC()->session->cart as $cart_item_key => $cart_item) {
                if ($product->id == $cart_item['product_id'] && isset($cart_item['subscription_switch'])) {
                    $is_purchasable = true;
                    break;
                }
            }
        }
    }
    return $is_purchasable;
}

add_filter('woocommerce_subscription_is_purchasable', 'fgc_is_purchasable', 20, 3);
add_filter('woocommerce_subscription_variation_is_purchasable', 'fgc_is_purchasable', 20, 3);

function fgc_addons_add_to_cart_url($add_to_cart_url) {
    if (isset($_POST['switch-subscription']) && false === strpos($add_to_cart_url, 'switch-subscription')) {
        $add_to_cart_url = WC_Subscriptions_Switcher::add_switch_query_args($_POST['switch-subscription'], $_POST['item'], $add_to_cart_url);
    }
    return $add_to_cart_url;
}

add_filter('addons_add_to_cart_url', 'fgc_addons_add_to_cart_url', 20);


add_action('init', 'tv_storefront_post_header', 50);

function tv_storefront_post_header() {
    remove_action('storefront_single_post', 'storefront_post_meta', 20);
    remove_action('storefront_single_post', 'storefront_post_header', 10);
    add_action('storefront_single_post', 'customer_storefront_post_header', 50);
}

function customer_storefront_post_header() {
    ?>
    <header class="entry-footer text-left">
        <?php
        if (is_single()) {
            $short_bitly_post_link = fgc_get_bitly_short_url(get_permalink());
            ?>
            <div class="signle_container">
                <input type="hidden" value="<?php echo $short_bitly_post_link; ?>" id="bitly_link" />
                <div class="col-sm-9 col-md-8">
                    <br/>
                    <p>
                        <a class="btnbgnone btnrow" href="/get-started"><span>Buy here </span> <i class="fa fa-angle-right hide"></i></a>
                    </p>
                    <p>
                        <a class="btnbgnone btnrow" href="/our-drink"><span>Read more about the ingredients here </span> <i class="fa fa-angle-right hide"></i></a>
                    </p>
                    <?php
                    tv_storefront_posted_on();
                    ?>
                    <?php
                    echo do_shortcode('[indeed_popups id=3]');
                    ?>
                    <a class="link-wiget-form-mobile" href="/free-sample/"><img src="/wp-content/themes/reize/assets/images/free/calltoaction-mobile.png" ></a>
                    <a class="link-wiget-form" href="/free-sample/"><img src="/wp-content/themes/reize/assets/images/free/calltoaction2.png" ></a>                    <p class="pbacktoblog">
                        <a class="arrowblack" href="/our-news">Back to Blog</a>
                    </p>
                    <div class="clearfix"></div>
                    <div class="mobile">
                        <?php dynamic_sidebar('sidebar-2'); ?>
                        <?php
                        /*
                          if (class_exists('Jetpack_RelatedPosts')) {
                          echo do_shortcode('[jetpack-related-posts]');
                          } */
                        ?>
                        <!--                        <div class="tv_relatedposts" id="tv_relatedposts">
                                                    <h3 class="tv_relatedposts_headline"><em>Related</em></h3>
                                                    <div class="clearfix"></div>
                                                    <ul class="tv_relatedposts_list">
                                                        <li>
                                                            <a href="">How to become a  morning person</a>
                                                        </li>
                                                        <li>
                                                            <a href="">The world first  energy drink barista</a>
                                                        </li>
                                                        <li>
                                                            <a href="">The wonderful  vitamin-b</a>
                                                        </li>
                                                        <li>
                                                            <a href="">6 reasons why reize is  the drink of choice  for thredbo</a>
                                                        </li>
                                                    </ul>
                                                </div>-->
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="let-do-this text-center text-uppercase">
                <a href="/get-started"><b>Join the reize club today</b></a>
            </div>
            <script>
                jQuery(window).load(function ($) {
                    current_url = window.location.href;
                    bitly_link = jQuery('#bitly_link').val();
                    jQuery('a.share-twitter').attr('href', 'http://www.twitter.com/share?&text=' + encodeURI('Great story! ') + '&url=' + bitly_link);
                    //                    jQuery('a.share-facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?description=' + encodeURI('Great story! ') + '&u=' + current_url);
                });</script>
            <?php
        } else {
            if ('post' == get_post_type()) {
                storefront_posted_on();
            }

            the_title(sprintf('<h1 class="entry-title" itemprop="name headline"><a href="%s" rel="bookmark">', esc_url(get_permalink())), '</a></h1>');
        }
        ?>
    </header><!-- .entry-header -->
    <?php
}

add_action('init', 'tv_storefront_post_content', 50);

function tv_storefront_post_content() {
    remove_action('storefront_single_post', 'storefront_post_content', 30);
    add_action('storefront_single_post', 'customer_storefront_post_content', 10);
}

function customer_storefront_post_content() {
    ?>
    <div class="entry-content" itemprop="articleBody">
        <?php
        storefront_post_thumbnail('full');
        ?>
        <div class="signle_container">
            <div class="col-sm-9 col-md-8">
                <?php
                the_title('<h1 class="entry-title font36" itemprop="name headline">', '</h1>');

                the_content(
                        sprintf(
                                __('Continue reading %s', 'storefront'), '<span class="screen-reader-text">' . get_the_title() . '</span>'
                        )
                );

                wp_link_pages(array(
                    'before' => '<div class="page-links">' . __('Pages:', 'storefront'),
                    'after' => '</div>',
                ));
                ?>
            </div>
            <div class="col-sm-3 col-md-4 desktop">
                <?php dynamic_sidebar('sidebar-2'); ?>
                <!--                <div class="tv_relatedposts" id="tv_relatedposts">
                                    <h3 class="tv_relatedposts_headline"><em>Related</em></h3>
                                    <div class="clearfix"></div>
                                    <ul class="tv_relatedposts_list">
                                        <li>
                                            <a href="">How to become a  morning person</a>
                                        </li>
                                        <li>
                                            <a href="">The world first  energy drink barista</a>
                                        </li>
                                        <li>
                                            <a href="">The wonderful  vitamin-b</a>
                                        </li>
                                        <li>
                                            <a href="">6 reasons why reize is  the drink of choice  for thredbo</a>
                                        </li>
                                    </ul>
                                </div>-->
            </div>
            <div class="clearfix"></div>
        </div>
    </div><!-- .entry-content -->
    <div class="clearfix"></div>
    <?php
}

if (!function_exists('tv_storefront_posted_on')) {

    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function tv_storefront_posted_on() {
        $time_string = '<time class="entry-date published updated" datetime="%1$s" itemprop="datePublished">%2$s</time>';
        if (get_the_time('U') !== get_the_modified_time('U')) {
            $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s" itemprop="datePublished">%4$s</time>';
        }

        $time_string = sprintf($time_string, esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_attr(get_the_modified_date('c')), esc_html(get_the_modified_date())
        );

        $posted_on = sprintf(
                _x('Posted on %s', 'post date', 'storefront'), '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">' . $time_string . '</a>'
        );

        $byline = sprintf(
                _x('Written by %s', 'post author', 'storefront'), '<span class="vcard author"><span class="fn" itemprop="author"><a class="url fn n" rel="author" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span></span>'
        );

        echo apply_filters('storefront_single_post_posted_on_html', '<span class="posted-on hide">' . $posted_on . '</span><span class="byline hide"> ' . $byline . '</span>', $posted_on, $byline);
    }

}

function tv_move_jp_sharing($content) {

    if (is_singular('post') && function_exists('sharing_display')) {
        remove_filter('the_content', 'sharing_display', 19);
        $content = sharing_display() . $content;
    }

    return $content;
}

add_filter('the_content', 'tv_move_jp_sharing');

function jetpackme_remove_rp() {
    if (class_exists('Jetpack_RelatedPosts')) {
        $jprp = Jetpack_RelatedPosts::init();
        $callback = array($jprp, 'filter_add_target_to_dom');
        remove_filter('the_content', $callback, 40);
    }
}

add_filter('wp', 'jetpackme_remove_rp', 20);


wp_localize_script('child-script', 'ajax_posts', array(
    'ajaxurl' => admin_url('admin-ajax.php'),
    'noposts' => __('No older posts found', 'twentyfifteen'),
));

function more_post_ajax() {

    $ppp = (isset($_POST["ppp"])) ? $_POST["ppp"] : 3;
    $page = (isset($_POST['pageNumber'])) ? $_POST['pageNumber'] : 0;
//    $cat = (isset($_POST['cat'])) ? $_POST['cat'] : '';
    header("Content-Type: text/html");

    $args = array(
        'suppress_filters' => true,
        'post_type' => 'post',
        'posts_per_page' => $ppp,
//        'cat' => $cat,
        'paged' => $page,
    );

    $loop = new WP_Query($args);

    $out = '';

    if ($loop->have_posts()) {
        while ($loop->have_posts()) : $loop->the_post();
            ?>
            <li class="item">
                <a href="<?php the_permalink(); ?>">
                    <?php
                    $thumbnail = get_the_post_thumbnail(null, $size, $attr);
                    if ($thumbnail == '') {
                        the_content();
                    } else {
                        echo $thumbnail;
                    }
                    ?>
                </a>
                <div class="item-content">
                    <h3 class="font20"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                    <?php fgc_get_short_description(get_the_ID()) ?>
                    <!--more-->
                    <br/>
                    <br/>
                    <?php // the_content();              ?>
                    <span class="read-more"><a href="<?php the_permalink(); ?>" class="font16">Read More</a></span>
                </div>
            </li>

            <?php
        endwhile;
    } else {
        ?>
        <script>
            jQuery(document).ready(function ($) {
                $('.load-more').removeAttr('id');
                $('.load-more').html('No more post.').css('cursor', 'default').css('width', '200px').css('border', 'none');
            });</script>
        <?php
    }
    wp_reset_postdata();
    die($out);
}

add_action('wp_ajax_nopriv_more_post_ajax', 'more_post_ajax');
add_action('wp_ajax_more_post_ajax', 'more_post_ajax');

register_sidebar(array(
    'name' => __('Sidebar signle post', 'storefront'),
    'id' => 'sidebar-2',
    'description' => '',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
));

function fgc_get_started($content) {
//    if (strpos($_SERVER["REQUEST_URI"], '/get-started')) {
    if (get_the_ID() == 56) {
        $subscription_result = FGC_ActiveCampaign::get_info_of_active_or_onhold_subscription(get_current_user_id());
        if ($subscription_result['has_subscription']) {
            ?>
            <script type="text/javascript">
                alert("You are already a <?php echo $subscription_result['current_drink'] ?> drinks per month REIZE Club member. You will now be redirected to 'My Account' page where you can manage your subscription.");
                window.location.href = "<?php echo get_site_url() . '/my-account'; ?>";
            </script>
            <?php
            exit();
        }
    }
    return $content;
}

add_filter('wp_head', 'fgc_get_started');

/**
 * Author: Phuong An <phuongantt.na@gmail.com>
 *
 * Remove sharing email
 * Disable Jetpack's open graph tags
 *
 */
// Remove shaing email send post action and override on jetpack_sharedaddy_override plugin
remove_action('sharing_email_send_post', 'sharing_email_send_post');

// Disable Jetpack's open graph tags to Facebook use the default og tags.
add_filter('jetpack_enable_opengraph', '__return_false', 99);

/**
 * get bitly short url
 * @author Ho Ngoc Hang
 * @param type $url
 * @return type
 */
function fgc_get_bitly_short_url($url) {
    $login = 'reize';
    $appkey = 'R_d18827a9ced642faae9c0496e86efe8d';
    $connectURL = 'http://api.bit.ly/v3/shorten?login=' . $login . '&apiKey=' . $appkey . '&uri=' . urlencode($url) . '&format=txt';
    return curl_get_result($connectURL);
}

/**
 * get result from Curl url
 * @author Ho Ngoc Hang
 * @param type $url
 * @return type
 */
function curl_get_result($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

add_action('init', 'fgc_custom_login');

/**
 * prevent customer access to core login/register of WP
 * @author: Ho Ngoc Hang
 * @global type $pagenow
 */
function fgc_custom_login() {
    global $pagenow;
    $action = isset($_GET['action']) ? $_GET['action'] : NULL;
    if (('wp-login.php' == $pagenow && $action == 'register') && strpos($_SERVER["REQUEST_URI"], 'wp-admin') === false) {
        $page = get_bloginfo('url') . '/login-page';
        wp_redirect($page);
        exit();
    }
}

add_action('init', 'fgc_check_logged_in');

function fgc_check_logged_in() {
    $current_path = $_SERVER["REQUEST_URI"];
    if (strpos($current_path, 'login-page'))
        if (get_current_user_id() > 0)
            if ($_COOKIE['page_before_login'] != '')
                wp_redirect($_COOKIE['page_before_login']);
}

/*
 * Add shortcode to Free Reize Banner in Homepage
 * @author: Hung Tran
 */

function freebanner_shortcode_func() {
    if (!is_user_logged_in()) {
        return '/login-page';
    } else {
        return '/my-account';
    }
}

add_shortcode('freebanner_shortcode', 'freebanner_shortcode_func');
//function test_dsc_func(){
//    echo 'Hello world';
//}
//add_shortcode('test_dsc', 'test_dsc_func');

/*
 * Modify og:description tag for facebook sharing in blog page.
 * @author: Hung Tran
 */
add_action('wp_head', 'my_wp_head');

function my_wp_head() {
    if (is_single()) {
        $post_id = get_queried_object_id();
        $excerpt = get_the_excerpt($post_id);
        $desc = '<meta property="og:description" content="' . esc_attr($excerpt) . '">';
        echo $desc;
    }
}

function wp_iframe_resizer_scripts() {
    wp_enqueue_script('iframe_autoheight', plugins_url('assets/js/jquery.autoheight.js', __FILE__), array('iframe_resizer'));
}

add_action('wp_enqueue_scripts', 'wp_iframe_resizer_scripts');

add_filter('body_class', 'fgc_custom_class');

function fgc_custom_class($classes) {
    $current_path = $_SERVER["REQUEST_URI"];
    if (strpos($current_path, 'get-started')) {
        $classes[] = 'get-started';
        $classes[] = 'category_page';
        $classes[] = 'subscription_category_page';
    }
    if (strpos($current_path, 'downgrade')) {
        $classes[] = 'downgrade-plan';
        $classes[] = 'category_page';
        $classes[] = 'subscription_category_page';
    }
    if (strpos($current_path, 'upgrade')) {
        $classes[] = 'upgrade-plan';
        $classes[] = 'category_page';
        $classes[] = 'subscription_category_page';
    }
    if (strpos($current_path, 'single-purchase') || is_page_template('christmas-landing.php')) {
        $classes[] = 'single-purchase';
        $classes[] = 'category_page';
    }
    return $classes;
}

add_action('init', 'myStartSession', 1);

function myStartSession() {
    if (!session_id()) {
        session_start();
    }
}