= $start_date) && ($date <= $end_date)) : setcookie('SESSpromoid', $promo_id, 0,'/'); setcookie('SESSpromotion_description', $promotion_description, 0,'/'); setcookie('SESSphone_number', $promophone_number, 0,'/'); setcookie('SESScoupon_code', $promocoupon_code , 0,'/'); //setcookie('SESSstart_date', $start_date , 0,'/'); //setcookie('SESSend_date', $end_date , 0,'/'); $_SESSION['SESSpromoid']=$promo_id; $_SESSION['SESSpromotion_description']=$promotion_description; $_SESSION['SESSphone_number']=$promophone_number; $_SESSION['SESScoupon_code']=$promocoupon_code; $_SESSION['SESSstart_date']=$start_date; $_SESSION['SESSend_date']=$end_date; endif; } endwhile; } if (!isset($_SESSION["SESSpromoid"])) { setcookie('SESSpromoid', 'WEB_ORG_0001', 0,'/'); setcookie('SESSpromotion_description', $lldefault_descr, 0,'/'); setcookie('SESSphone_number', $lldefault_phone, 0,'/'); $_SESSION['SESSpromoid']="WEB_ORG_0001"; $_SESSION['SESSpromotion_description']=$lldefault_descr; $_SESSION['SESSphone_number']=$lldefault_phone; } # Imports all Composer packages require __DIR__ . '/vendor/autoload.php'; use ofc\Site; # Declare a new Site object $site = new Site(); # Allow the Site object to be accessed in other files function site() { global $site; return $site; } /** * Register Custom Navigation Walker */ add_action('after_setup_theme', function () { require_once get_template_directory() . '/bootstrap_5_wp_nav_menu_walker.php'; }); register_nav_menu('consumer-menu', 'Consumer menu'); register_nav_menu('business-menu', 'Buisness menu'); register_nav_menu('col-one-consumer-menu', 'Col 1 Consumer Menu'); register_nav_menu('col-two-consumer-menu', 'Col 2 Consumer Menu'); register_nav_menu('col-three-consumer-menu', 'Col 3 Consumer Menu'); register_nav_menu('col-four-consumer-menu', 'Col 4 Consumer Menu'); register_nav_menu('col-one-business-menu', 'Col 1 Business Menu'); register_nav_menu('col-two-business-menu', 'Col 2 Business Menu'); register_nav_menu('col-three-business-menu', 'Col 3 Business Menu'); register_nav_menu('col-four-business-menu', 'Col 4 Business Menu'); /** * Adds selected style sheet option as a class on body element */ add_filter('body_class', function ($class) { $style_sheet = get_field('style_sheet'); // default to consumer brand if we don't have the ACF option for the current page if (!$style_sheet) { $style_sheet = "consumer-brand"; } $class[] = $style_sheet; return $class; }); /** * Creates a custom excerpt from an ACF post object */ function custom_excerpt($str, $length = 70, $append = '...') { $pieces = explode(' ', strip_tags($str)); $excerpt = implode(' ', array_slice($pieces, 0, $length)); if (count($pieces) > $length) { $excerpt .= $append; } return $excerpt; } /** * Replaces post excerpt truncate and sets as a link */ function wpdocs_excerpt_more( $more ) { if ( ! is_single() ) { $more = sprintf( '%2$s', get_permalink( get_the_ID() ), __( ' Read more >>', 'textdomain' ) ); } return $more; } add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); /** * WooCommerce Support */ add_action('after_setup_theme', function () { 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'); remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0); /* Disable all payment gateways at checkout */ add_filter('woocommerce_cart_needs_payment', '__return_false'); // Disable different woocommerce notifications add_filter('woocommerce_cart_item_removed_notice_type', '__return_false'); add_filter('wc_add_to_cart_message_html', '__return_false'); // when a new item gets added to the cart, empty the cart of previous items // and purge add ons add_filter('woocommerce_add_to_cart_validation', function ($passed, $product_id, $quantity) { if (!WC()->cart->is_empty()) { WC()->cart->empty_cart(); } $_SESSION["addOns"] = []; $_SESSION["one-time"] = []; return $passed; }, 20, 3); add_filter('woocommerce_checkout_fields', function ($fields) { // $fields['order']['order_comments']['placeholder'] = 'My new placeholder'; return $fields; }); }); // WooCommerce Fee Stuff // first, wordpress doesn't use sessions, so let's enable those add_action('init', function () { if (!session_id()) { session_start(); } }); // and clean up sessions on logout add_action('wp_logout', function () { session_destroy(); }); // $_SESSION values are set on the cart page add_action('woocommerce_cart_calculate_fees', function () { $coupons_val = WC()->cart->get_applied_coupons(); $cart = WC()->cart; $cart_contents = $cart->get_cart(); foreach ($cart_contents as $cart_item_key => $cart_item): endforeach; if (isset($_SESSION["Activation Fee"]) && !in_array("free-activation", $coupons_val)) { $cartItem = null; foreach (WC()->cart->get_cart() as $i) { $cartItem = $i; } $feeLabel = get_field("fee_type", $cartItem["product_id"]); WC()->cart->add_fee($feeLabel, $_SESSION["Activation Fee"]); } $attributeRatePlan = $cart_item['variation']['attribute_rate-plan']; $keylb = $_SESSION["addOns"]["Key Lockbox"]; $onetimepo = $_SESSION['one-time']; $proInstall = $_SESSION["one-time"]; if (isset($proInstall)) { WC()->cart->add_fee('Professional Install', 99.00); } $rate_multiplier = 1; if ($attributeRatePlan === "Semi-Annually") { $rate_multiplier = 6; } elseif ($attributeRatePlan === "Annually") { $rate_multiplier = 12; } elseif ($attributeRatePlan === "Monthly") { $rate_multiplier = 1; } $cart_items = WC()->cart->get_cart_contents(); foreach ($_SESSION["addOns"] as $addOn) { if ($attributeRatePlan === "Annually" && $addOn["label"] === "Key Lockbox") { WC()->cart->add_fee($addOn["label"], 0); } elseif (!isset($cart_items[$addOn["label"]])) { WC()->cart->add_fee($addOn["label"], $addOn["price"] * $rate_multiplier); } } }); /** * Allow only one coupon per order in WooCommerce. */ add_filter('woocommerce_apply_individual_use_coupon', 'only_one_coupon_allowed', 10, 2); function only_one_coupon_allowed($apply, $coupon) { // Check if a coupon is already applied if (WC()->cart->has_discount()) { // Remove other applied coupons except the current one WC()->cart->empty_discounts(); WC()->cart->apply_coupon($coupon->get_code()); return false; // Do not apply the new coupon } return $apply; } add_filter('woocommerce_add_error', 'customize_coupon_error_message', 10, 1); function customize_coupon_error_message($error) { // Check if the error message is related to a coupon already applied if (strpos($error, 'Coupon code already applied!') !== false) { return ''; // Return an empty string to suppress this specific error message } return $error; // Return the original error message if it's not related to coupons } add_action('woocommerce_cart_calculate_fees', 'add_setup_fees'); function add_setup_fees($cart) { // Check if the cart has any coupons applied if (empty($cart->get_applied_coupons())) { return; // Exit if no coupons are applied } // Loop through each applied coupon foreach ($cart->get_applied_coupons() as $coupon_code) { // Get the coupon object $coupon = new WC_Coupon($coupon_code); // Get the coupon ID $coupon_id = $coupon->get_id(); // Get the terms (categories) associated with this coupon $coupon_categories = wp_get_post_terms($coupon_id, 'sc_coupon_category', array('fields' => 'ids')); } } /** * Generates a cart summary based on your current state * * @return string */ function generateCartSummary($showCheckoutButton = true) { global $product; WC()->session->set('chosen_shipping_methods', array( 'flat_rate:2' ) ); $shipping_methods = WC()->session->get('chosen_shipping_methods'); $cartItem = null; foreach (WC()->cart->get_cart() as $i) { $cartItem = $i; } $product = site()->getPost($cartItem["product_id"], [ "title", "thumbnail", "acf.activation_fee", "acf.fee_type", "meta._regular_price", "shipCoupon", "shipCouponName", "defaultShipping", "shippingName", "couponList", "couponTotal", "activationFeeName", "activationFeeAmount", ]); // starting aggrigate costs $coupon = WC()->cart->applied_coupons; $productMonthly = $product["_regular_price"]; $oneTimeCostsFee = $product["activation_fee"]; // AKA Setup fee $activationFeeName = $product["fee_type"]; $cart = WC()->cart; $cart_contents = $cart->get_cart(); foreach ($cart_contents as $cart_item_key => $cart_item): $monthlyCosts = $cart_item['data']->get_regular_price(); endforeach; $coupons_name = WC()->cart->applied_coupons; $prof_install_code = WC()->cart->has_discount( 'x8gt58at' ); $activation_coupon = array("l8dd","p43d","k4bu","m4jc","p584","s2bt"); $method_rate_id = 'flat_rate:2'; $shipping_type = get_title_shipping_method_from_method_id( $method_rate_id ); $cart_shipping_val= WC()->session->get('cart_totals')['shipping_total']; $shippingPrice = (float)'29.95'; $applied_coupon = WC()->cart->get_applied_coupons(); $discount = $applied_coupon->amount; $price_type = $addOn["price_type"]; $coupon = WC()->cart->get_coupons(); foreach ($coupon as $key => $coupon_value) { $coupon_amount = $coupon_value->amount; } $s_applied_coupons = WC()->cart->get_applied_coupons(); foreach( $s_applied_coupons as $scoupon_code ){ $scoupon = new WC_Coupon($scoupon_code); $coupon_type = $scoupon->get_discount_type(); $is_free_shipping = $scoupon->get_free_shipping(); if ($coupon_type == 'percent') { $coupon_total = ($scoupon->amount / 100); $coupon_subtotal = ($monthlyCosts * 12) * $coupon_total; $samount = number_format($coupon_subtotal, 2); $coupon_title = "Discount"; $coupon_amount = $samount; } if ($coupon_type == 'fixed_product') { if ($is_free_shipping) { $samount = (float)'29.95'; } } if ($coupon_type == 'fixed_cart') { $coupon_title = "Discount"; $samount = $scoupon->amount; } } // Get all coupons $coupons = get_posts(array( 'post_type' => 'shop_coupon', 'posts_per_page' => -1, 'post_status' => 'publish', )); // Extract post excerpt $post_excerpt = get_the_excerpt(); // Filter coupons based on the post excerpt $filtered_coupons = array_filter($coupons, function($coupon) { return $coupon->post_excerpt === "Free activation"; }); // $filtered_coupons contains coupons where the post excerpt is "Free activation" foreach( $applied_coupon as $coupon_code ){ $coupon = new WC_Coupon($coupon_code); $freeship_coupon = $coupon->get_free_shipping(); if ($freeship_coupon) { WC()->session->set('chosen_shipping_methods', array( 'free_shipping:4' ) ); $freeship_name = "Free Shipping"; $pro_coupon = (float)'29.95'; } } $proInstall = $_SESSION["one-time"]; if (isset($proInstall)) { WC()->session->set('chosen_shipping_methods', array( 'free_shipping:4' ) ); $available_methods = WC()->shipping->packages[0]['rates']; $shipping_method_1 = WC_Shipping_Zones::get_shipping_method(4 ); $shipping_methods = WC()->session->get('chosen_shipping_methods'); $freeship_name = "Free Shipping"; $freeship_discount = WC()->cart->get_coupon_discount_totals(); $professional_onetime = (float)'99.00'; $shipping_total = (float)'29.95'; $pro_coupon = (float)'29.95'; } $cart = WC()->cart; $cart_contents = $cart->get_cart(); foreach ($cart_contents as $cart_item_key => $cart_item): endforeach; $variable_price = $cart_item['data']->get_regular_price(); $fees = WC()->cart->get_fees(); $attributeRatePlan = $cart_item['variation']['attribute_rate-plan']; $keylb = $_SESSION["addOns"]["Key Lockbox"]; // Separate add-ons $fallDetection = array_filter($_SESSION["addOns"], function($item) { return $item["label"] === "Fall Detection"; }); $protectionPlan = array_filter($_SESSION["addOns"], function($item) { return $item["label"] === "Protection Plan"; }); $keyLockbox = array_filter($_SESSION["addOns"], function($item) { return $item["label"] === "Key Lockbox"; }); // Store label and price in individual variables $fallDetectionLabel = reset($fallDetection)["label"]; $fallDetectionPrice = reset($fallDetection)["price"]; $protectionPlanLabel = reset($protectionPlan)["label"]; $protectionPlanPrice = reset($protectionPlan)["price"]; $keyLockboxLabel = reset($keyLockbox)["label"]; $keyLockboxPrice = reset($keyLockbox)["price"]; if (is_iterable($_SESSION["addOns"])) { foreach ($_SESSION["addOns"] as $addOn) { // every addOn should have a price_type, so let's skip any oddities if (!isset($addOn["price_type"])) { continue; } } } if ($attributeRatePlan === "Monthly") { $total_cart = $oneTimeCostsFee + $fallDetectionPrice + $protectionPlanPrice + $keyLockboxPrice + $monthlyCosts + $professional_onetime + $shippingPrice - $pro_coupon ; $addon_price; } elseif($attributeRatePlan === "Semi-Annually") { WC()->session->set('chosen_shipping_methods', array( 'free_shipping:4' ) ); $variable_price = (float)($variable_price * 6); $fallDetectionPrice = (float)($fallDetectionPrice * 6); $protectionPlanPrice = (float)($protectionPlanPrice * 6); $keyLockboxPrice = (float)($keyLockboxPrice * 6); $available_methods = WC()->shipping->packages[0]['rates']; $shipping_method_1 = WC_Shipping_Zones::get_shipping_method(4 ); $shipping_methods = WC()->session->get('chosen_shipping_methods'); $freeship_name = "Free Shipping"; $freeship_discount = WC()->cart->get_coupon_discount_totals(); $shipping_total = (float)'29.95'; if (isset($s_applied_coupons)) { $sub_total = ($monthlyCosts * 6) + $oneTimeCostsFee; $discount_subtotal = ($monthlyCosts * 6) - $samount; $formattedDiscountTotal = number_format($discount_subtotal, 2); $total_cart = $sub_total + $fallDetectionPrice + $protectionPlanPrice + $keyLockboxPrice + $professional_onetime - $samount; } else { $sub_total = ($monthlyCosts * 6) + $oneTimeCostsFee; $total_cart = $sub_total + $fallDetectionPrice + $protectionPlanPrice + $keyLockboxPrice + $professional_onetime; } } elseif($attributeRatePlan === "Annually") { $variable_price = (float)($variable_price * 12); $protectionPlanPrice = (float)($protectionPlanPrice * 12); $fallDetectionPrice = (float)($fallDetectionPrice * 12); WC()->session->set('chosen_shipping_methods', array( 'free_shipping:4' ) ); $available_methods = WC()->shipping->packages[0]['rates']; $shipping_method_1 = WC_Shipping_Zones::get_shipping_method(4 ); $shipping_methods = WC()->session->get('chosen_shipping_methods'); $freeship_name = "Free Shipping"; $freeship_discount = WC()->cart->get_coupon_discount_totals(); //$shipping_total = WC()->cart->get_shipping_total(); $shipping_total = (float)'29.95'; $free_keylockbox = "Key Lockbox"; if (isset($_SESSION['addOns']['Key Lockbox'])) { $keyLockboxPrice = $_SESSION['addOns']['Key Lockbox']['price'] = '0.00'; } if (isset($s_applied_coupons)) { $sub_total = ($monthlyCosts * 12) + $oneTimeCostsFee; $discount_subtotal = ($monthlyCosts * 12) - $samount; $formattedDiscountTotal = number_format($discount_subtotal, 2); $total_cart = $sub_total + $fallDetectionPrice + $protectionPlanPrice + $professional_onetime - $samount; } else { $sub_total = ($monthlyCosts * 12) + $oneTimeCostsFee; $total_cart = $sub_total + $fallDetectionPrice + $protectionPlanPrice + $professional_onetime; } } $proinstall_label = $_SESSION["one-time"]["Professional Install"]["label"]; $fees = WC()->cart->get_fees(); $applied_coupons = WC()->cart->get_applied_coupons(); foreach ($applied_coupons as $coupon_code) { $coupon = new WC_Coupon($coupon_code); $coupon_description = $coupon->get_description(); } $free_activation_category = array( 'numberposts' => -1, 'post_type' => 'shop_coupon', 'orderby' => 'date', 'tax_query' => array( array( 'taxonomy' => 'sc_coupon_category', 'field' => 'term_id', 'terms' => array(54), ), ), ); // Get all coupons in the 'six_for_six' category (term_id = 55) $six_for_six = array( 'numberposts' => -1, 'post_type' => 'shop_coupon', 'orderby' => 'date', 'tax_query' => array( array( 'taxonomy' => 'sc_coupon_category', 'field' => 'term_id', 'terms' => array(55), ), ), ); $sixforsix_category = get_posts($six_for_six); // Get all coupons in the 'five_off' category (term_id = 56) $five_off = array( 'numberposts' => -1, 'post_type' => 'shop_coupon', 'orderby' => 'date', 'tax_query' => array( array( 'taxonomy' => 'sc_coupon_category', 'field' => 'term_id', 'terms' => array(56), ), ), ); $category_coupons = get_posts($free_activation_category); foreach ($category_coupons as $coupon) { } foreach ($cart->get_applied_coupons() as $coupon_code) { $coupon = new WC_Coupon($coupon_code); $coupon_id = $coupon->get_id(); $coupon_categories = wp_get_post_terms($coupon_id, 'sc_coupon_category', array('fields' => 'ids')); if (in_array(55, $coupon_categories)) { $is_sixforsix_applied = true; } if (in_array(56, $coupon_categories)) { $is_fiveoff_applied = true; } } if ($is_sixforsix_applied || $is_fiveoff_applied) { $coupon_amount = $coupon->amount; } return site()->render("cart_summary", array_merge($product, [ "variable_price" => $variable_price, "addonPrice" => $addon_price, "variation" => $attributeRatePlan, "fallDetectionLabel" => $fallDetectionLabel, "fallDetectionPrice" => $fallDetectionPrice, "protectionPlan" => $protectionPlanLabel, "protectionPlanprice" => $protectionPlanPrice, "keyLockboxlabel" => $keyLockboxLabel, "keylockboxprice" => $keyLockboxPrice, "one-time" => $proinstall_label, "pro-one-time" => $professional_onetime, "couponList" => $coupon_title, "couponTotal" => $coupon_amount, "defaultShipping" => $shippingPrice, "shippingName" => $shipping_type, "shipCoupon" => $shipping_total, "shipCouponName" => $freeship_name, "totalMonthly" => $monthlyCosts, "activationFeeName" => $activationFeeName, "activationFeeAmount" => $oneTimeCostsFee, "programming_fee_name" => $programming_fee_name, "programming_fee_val" => $programming_fee_val, "totalDue" => $total_cart, "showCheckoutButton" => $showCheckoutButton, "couponSummary" => $couponSummary, "couponDescription" => $coupon_description, "checkboxes" => get_field("cart_preview_checklist", "options"), ])); } function update_cart_prices($cart) { foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { $product_id = $cart_item['product_id']; $product = wc_get_product($product_id); $variation_id = $cart_item['variation_id']; $variation = wc_get_product($variation_id); $variation_price = $variation->get_price(); if ($product && isset($cart_item['variation']['attribute_rate-plan'])) { $attributeRatePlan = $cart_item['variation']['attribute_rate-plan']; $multiplier = 1; switch ($attributeRatePlan) { case 'Annually': $multiplier = 12; break; case 'Semi-Annually': $multiplier = 6; break; case 'Monthly': $multiplier = 1; break; } $updated_price = $variation_price * $multiplier; // Update the price in the cart item data array $cart->cart_contents[$cart_item_key]['data']->set_price($updated_price); } } } add_action('woocommerce_before_calculate_totals', 'update_cart_prices'); function get_title_shipping_method_from_method_id( $method_rate_id = '' ){ if( ! empty( $method_rate_id ) ){ $method_key_id = str_replace( ':', '_', $method_rate_id ); $option_name = 'woocommerce_'.$method_key_id.'_settings'; return get_option( $option_name, true )['title']; } else { return false; } } function add_administration_fees() { WC()->cart->add_fee( 'Processing Fee', 2.5 ); } /** * custom woocommerce order fields */ $additionalWooFields = [ "subscriber_first_name" => [ "type" => "text", "label" => "", "placeholder" => "First Name", "required" => true, ], "subscriber_last_name" => [ "type" => "text", "label" => "", "placeholder" => "Last Name", "required" => true, ], "subscriber_address_1" => [ "type" => "text", "label" => "", "placeholder" => "Address 1", "required" => true, ], "subscriber_address_2" => [ "type" => "text", "label" => "", "placeholder" => "Address 2 (Apt, Suite, etc.)", ], "subscriber_zip" => [ "type" => "text", "label" => "", "placeholder" => "Zip Code", "required" => true, ], "subscriber_city" => [ "type" => "text", "label" => "", "placeholder" => "City", "required" => true, ], "subscriber_state" => [ "type" => "text", "label" => "", "placeholder" => "State", "required" => true, ], "subscriber_email" => [ "type" => "text", "label" => "", "placeholder" => "Email Address", ], "subscriber_phone" => [ "type" => "text", "label" => "", "placeholder" => "Phone Number", ], "caregiver_relation" => [ "type" => "select", "label" => "Relation", "options" => [ "Brother" => "Brother", "Daughter" => "Daughter", "Father" => "Father", "Friend" => "Friend", "Granddaughter" => "Granddaughter", "Grandson" => "Grandson", "In-law" => "In-law", "Mother" => "Mother", "Neighbor" => "Neighbor", "Relative" => "Relative", "Sister" => "Sister", "Son" => "Son", "Spouse" => "Spouse", "Other" => "Other", ], "required" => true, ], "caregiver_first_name" => [ "type" => "text", "label" => "", "placeholder" => "First Name", "required" => true, ], "caregiver_last_name" => [ "type" => "text", "label" => "", "placeholder" => "Last Name", "required" => true, ], "caregiver_email" => [ "type" => "text", "label" => "", "placeholder" => "Email Address", ], "caregiver_phone" => [ "type" => "text", "label" => "", "placeholder" => "Phone Number", ], "card_number" => [ "type" => "number", "label" => "Credit Card", "required" => true, ], "ccv" => [ "type" => "number", "label" => "CCV", "required" => true, ], "expiration_month" => [ "type" => "number", "label" => "Expiration Month", "required" => true, "attrs" => ["min" => 1, "max" => 12, "step" => 1] ], "expiration_year" => [ "type" => "number", "label" => "Expiration Year", "required" => true, "attrs" => ["min" => 2022, "max" => 2032, "step" => 1] ], "SESSpromoid" => [ "type" => "hidden", "label" => "Promotion ID", ], "SESSpromotion_description" => [ "type" => "hidden", "label" => "Promotion Description", ], "SESScoupon_code" => [ "type" => "hidden", "label" => "Coupon Code", ], ]; add_action('woocommerce_before_checkout_billing_form', function ($checkout) use ($additionalWooFields) { $dto = []; foreach ($additionalWooFields as $key => $field) { ob_start(); $customAttributes = ["v-model" => $key]; if ($field["attrs"]) { $customAttributes = array_merge($customAttributes, $field["attrs"]); } woocommerce_form_field($key, [ 'type' => $field["type"], 'class' => $field["classes"] ?? ['my-field-class orm-row-wide'], 'input_class' => $field["input_classes"] ?? [], 'label_class' => $field["label_classes"] ?? [], 'label' => $field["label"] ?? $key, 'required' => $field["placeholder"] ?? false, 'placeholder' => $field["placeholder"] ?? "", 'options' => $field["options"] ?? [], 'custom_attributes' => $customAttributes, ], $checkout->get_value($key)); $fieldHTML = ob_get_contents(); ob_end_clean(); $dto[$key] = $fieldHTML; } echo site()->render("checkout-step-1", $dto); }); function showCardFields() { global $additionalWooFields; $dto = []; foreach ($additionalWooFields as $key => $field) { if (!in_array($key, ["card_number", "ccv", "expiration_month", "expiration_year"])) { continue; } ob_start(); $customAttributes = ["v-model" => $key]; if ($field["attrs"]) { $customAttributes = array_merge($customAttributes, $field["attrs"]); } woocommerce_form_field($key, [ 'type' => $field["type"], 'class' => $field["classes"] ?? ['my-field-class orm-row-wide'], 'input_class' => $field["input_classes"] ?? [], 'label_class' => $field["label_classes"] ?? [], 'label' => $field["label"] ?? $key, 'required' => $field["placeholder"] ?? false, 'placeholder' => $field["placeholder"] ?? "", 'options' => $field["options"] ?? [], 'custom_attributes' => $customAttributes, ], null); $fieldHTML = ob_get_contents(); ob_end_clean(); $dto[$key] = $fieldHTML; } echo site()->render("card-fields", $dto); } add_action('woocommerce_checkout_update_order_meta', function ($orderID) use ($additionalWooFields) { foreach ($additionalWooFields as $key => $field) { if (isset($_POST[$key])) { $value = esc_attr($_POST[$key]); if ($key === "card_number") { $parts = str_split($value); $output = ""; for ($i = 0; $i < count($parts); $i++) { if ($i < count($parts) - 4) { $output .= "*"; } else { $output .= $parts[$i]; } } $value = $output; } update_post_meta($orderID, $key, $value); } } }); add_action('woocommerce_admin_order_data_after_shipping_address', function ($order) use ($additionalWooFields) { $dto = [ "subscriber-data" => [], "caregiver-data" => [], ]; foreach ($additionalWooFields as $key => $field) { $meta = get_post_meta($order->get_id(), $key, true); $dataType = (substr($key, 0, 10) === "subscriber") ? "subscriber-data" : "caregiver-data"; $dto[$dataType][] = [ "label" => $field["label"] ? $field["label"] : $field["placeholder"], "value" => $meta ?: "", ]; } echo site()->render("order_details_in_admin", $dto); }); function update_individual_fields_11($entry, $form) { echo '
'; echo '
'; $aarpval = rgpost('input_3', true); $aarp_val = str_replace(' ', '', $aarpval); return $aarp_val; global $aarp_val; } // AARP API add_filter('gform_get_form_filter', 'shortcode_unautop', 11); add_filter('gform_get_form_filter', 'do_shortcode', 11); add_action('gform_pre_submission_7', 'aarp_api'); function aarp_api() { $app_id = 'prodAppId'; $app_secret = 'prodSecret@123'; $aarpval = rgpost('input_3', true); $aarp_val = str_replace(' ', '', $aarpval); $apiUrl = 'https://selfserviceportal.lifeline.com/api/address/v1/affiliates/verify?externalIdType1=memberId&externalIdValue1=' . $aarp_val .'&affiliate=AARP'; $request = wp_remote_get($apiUrl, array('timeout' => 10, 'sslverify' => false, 'headers' => array('appId' => $app_id, 'appSecret' => $app_secret, 'Content-Type' => 'application/json'))); $body = wp_remote_retrieve_body($request); $result = json_decode($body, true); $memberstatus = $result["status"]; if ($memberstatus == "ACTIVE") { add_shortcode('aarpCode', 'aarp_form'); $aarp_coupon = "E6Y8"; $_SESSION['SSESSmember']=$aarp_coupon; } else { add_shortcode('aarpCode', 'aarp_form_notfound'); } } function aarp_form() { $aarp_member .= '

Membership Verified

Thank you for providing your Member ID, your discount code will be applied to the your product selection.

Your discount code is:

E6Y8

'; return $aarp_member; global $aarp_member; } function aarp_form_notfound() { $aarp_member_notfound .= '

Membership record could not be found.

We could not find the AARP Membership you entered. Please re-type your number and try again. If that does not work, or you need assistance, please call our customer service team: 1-855-345-0130

Try Again

'; return $aarp_member_notfound; global $aarp_member_notfound; } /** * Function get_phone * * Get phone number from database, campaigns and google forwarding numbers * */ function get_phone() { if (isset($_SESSION['SESSphone_number'])) { $num = $_SESSION["SESSphone_number"]; $ufnum = preg_replace("/[^0-9]/", "", $num); $fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6); return $fnum; global $fnum; } else { $num = get_option('cta_tel', true); $ufnum = preg_replace("/[^0-9]/", "", $num); $fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6); return $fnum; global $fnum; } } add_shortcode('op', 'get_phone'); add_filter('gform_field_value_SESSpromoid', 'populate_SESSpromoid'); function populate_SESSpromoid($value) { if (isset($_SESSION["SESSpromoid"])) { return $_SESSION["SESSpromoid"]; } else { return ''; }; }; add_filter('gform_field_value_SESScoupon_code', 'populate_SESScoupon_code'); function populate_SESScoupon_code($value) { if (isset($_SESSION["SESScoupon_code"])) { return $_SESSION["SESScoupon_code"]; } else { return ''; }; }; add_filter('gform_field_value_SESSpromotion_description', 'populate_SESSpromotion_description'); function populate_SESSpromotion_description($value) { if (isset($_SESSION["SESSpromotion_description"])) { return $_SESSION["SESSpromotion_description"]; } else { return ''; }; }; $newStatuses = [ 'wc-sent-to-sales-rep' => 'Sent to Sales Rep', 'wc-test-lead' => 'Test Lead', 'wc-duplicate-lead' => 'Duplicate Lead', ]; add_action('init', function () use ($newStatuses) { foreach ($newStatuses as $key => $label) { register_post_status($key, [ 'label' => $label, 'public' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true, 'exclude_from_search' => false, 'label_count' => _n_noop($label . ' (%s)', $label . ' (%s)') ]); } }); add_filter('wc_order_statuses', function ($order_statuses) use ($newStatuses) { foreach ($order_statuses as $key => $status) { $new_order_statuses[$key] = $status; if ('wc-processing' === $key) { foreach ($newStatuses as $key => $label) { $new_order_statuses[$key] = $label; } } } return $new_order_statuses; }); // auto apply the AARP coupon add_action("woocommerce_before_checkout_form", function () { if (isset($_SESSION["SSESSmember"]) && $_SESSION["SSESSmember"]) { $code = strtolower($_SESSION["SSESSmember"]); WC()->cart->apply_coupon($code); } if (isset($_SESSION["SESScoupon_code"]) && $_SESSION["SESScoupon_code"]) { $couponcode = strtolower($_SESSION["SESScoupon_code"]); if (in_array(strtolower($_SESSION["SESScoupon_code"]), WC()->cart->get_applied_coupons())) { return; } WC()->cart->apply_coupon($couponcode); } }); add_filter( 'woocommerce_order_shipping_to_display_shipped_via', '__return_false' ); /** * Update order emails to include all the extra stuff */ add_filter('woocommerce_email_order_meta_fields', function ($fields, $sent_to_admin, $order) use ($additionalWooFields) { foreach ($additionalWooFields as $key => $value) { $fields[$key] = [ 'label' => strlen($value["label"]) ? $value["label"] : $value["placeholder"], 'value' => get_post_meta($order->id, $key, true), ]; } if (count($order->get_coupon_codes())) { $fields["applied_coupons"] = [ "label" => "Applied Coupons", "value" => implode(", ", $order->get_coupon_codes()), ]; } return $fields; }, 10, 3); add_action('woocommerce_thankyou', function ($order_id) { $order = wc_get_order($order_id); //wc_get_template( 'order/order-details-customer.php', array('order' => $order )); foreach( $order->get_items() as $item ){ $item_data = $item->get_data(); $formatted_meta_data = $item->get_formatted_meta_data( '_', true ); } foreach ( $order->get_fees() as $fees ) $coupon = new WC_Coupon( $coupon_code ); $product_subtotal = $order->subtotal; // 29.95 $order_total = (float)$order->get_total(); $shipping = (float)$order->discount_total; $coupon_total = (float)$coupon->amount; // $50.00 foreach( $order->get_coupon_codes() as $coupon_code ) { $coupon = new WC_Coupon( $coupon_code ); $count = $coupon->get_usage_count(); $limit = $coupon->get_usage_limit_per_user(); if ( ! empty ( $count ) && ! empty ( $limit ) ) { $remaining = $limit - $count; } } if ($order->shipping_total == 0) { $shipping_label = 'Shipping'; $freeshipping_cost = 'Free'; } else { $shipping_label = 'Shipping'; $shipping_cost = $order->shipping_total; } $coupon_amount = $order->discount_total; if ($coupon_amount == 0) { unset($coupon_code); } echo site()->render("thank-you-order-details", [ "setupFeePrice" => $fees->get_amount(), "setupFeeName" => $fees->get_name(), "couponCode" => $coupon_code, "couponAmount" => $coupon_amount, "monthlyFee" => $order->subtotal, "shippingLabel" => $shipping_label, "shippingCost" => $shipping_cost, "freeshippingCost" => $freeshipping_cost, "items" => array_map(function ($i) { return [ "name" => $i->get_name(), "image" => $i->get_product()->get_image([100, 100]), ]; }, $order->get_items()), "total" => $order->get_total(), "fees" => array_map(function ($f) { return [ "name" => $f->get_name(), "amount" => $f->get_amount(), ]; }, $order->get_fees()), ]); }); /** * Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure * * @author Golden Oak Web Design * @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2+ */ function blog_generate_rewrite_rules( $wp_rewrite ) { $new_rules = array( '(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]', 'blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1', 'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true', 'blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1', 'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]', 'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]', 'blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]', 'blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]', 'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]', 'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]', 'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]', 'blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]', 'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1', 'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]', ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action( 'generate_rewrite_rules', 'blog_generate_rewrite_rules' ); function update_post_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( is_object( $post ) && $post->post_type == 'post' ) { return home_url( '/blog/' . $post->post_name . '/'); } return $post_link; } add_filter( 'post_link', 'update_post_link', 1, 3 ); function skip_redirect( $skip_redirect, $post_id, $post ) { if ( $post->post_type === 'post' ) { $skip_redirect = true; } return $skip_redirect; } add_filter( 'wpseo_premium_post_redirect_slug_change', 'skip_redirect', 10, 3 ); // Google Tag Manager add_action( 'wp_head', 'gtm_output', 2 ); add_action( 'wp_footer', 'gtm_datalayer_init', 10 ); add_action( 'body_top', 'gtm_noscript_output' ); function gtm_output() { ?> cart->is_empty()) { unset($_SESSION["one-time"]); unset($_SESSION["addOns"]); $woocommerce->cart->empty_cart(); } return $cart_item_data; } add_filter('woocommerce_checkout_fields', 'customize_billing_fields'); function customize_billing_fields($fields) { unset($fields['billing']['billing_company']); $fields['billing']['billing_first_name']['label'] = ''; $fields['billing']['billing_last_name']['label'] = ''; $fields['billing']['billing_address_1']['label'] = ''; $fields['billing']['billing_address_2']['label'] = ''; $fields['billing']['billing_city']['label'] = ''; $fields['billing']['billing_postcode']['label'] = ''; $fields['billing']['billing_phone']['label'] = ''; $fields['billing']['billing_email']['label'] = ''; $fields['billing']['billing_state']['label'] = ''; $fields['billing']['billing_state']['placeholder'] = 'Select Your State'; $fields['billing']['billing_first_name']['placeholder'] = __('First Name', 'woocommerce'); $fields['billing']['billing_last_name']['placeholder'] = __('Last Name', 'woocommerce'); $fields['billing']['billing_address_1']['placeholder'] = __('Street address', 'woocommerce'); $fields['billing']['billing_address_2']['placeholder'] = __('Apartment, suite, unit etc. (optional)', 'woocommerce'); $fields['billing']['billing_city']['placeholder'] = __('City', 'woocommerce'); $fields['billing']['billing_postcode']['placeholder'] = __('Postcode / ZIP', 'woocommerce'); $fields['billing']['billing_phone']['placeholder'] = __('Phone', 'woocommerce'); $fields['billing']['billing_email']['placeholder'] = __('Email address', 'woocommerce'); return $fields; }