theme updates
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
<?php
|
||||
|
||||
// To complete at at later date
|
||||
//add_action('wp_enqueue_scripts', 'enqueue_google_maps_autocomplete');
|
||||
|
||||
function enqueue_google_maps_autocomplete() {
|
||||
wp_enqueue_script( 'auto-complete', get_template_directory_uri().'/vendor/google/auto-complete.js');
|
||||
}
|
||||
|
||||
// To complete at at later date
|
||||
// add_action ( 'wp_head', 'googleapi' );
|
||||
|
||||
function googleapi(){
|
||||
?>
|
||||
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCgGXpHzX95Ew5Da21PvSp6mEXFA78OTYQ&libraries=places&callback=initAutocomplete" ></script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
session_start();
|
||||
$utm_campaign = $_GET['promotion_id'];
|
||||
|
||||
@@ -174,33 +193,15 @@ add_action('woocommerce_cart_calculate_fees', function () {
|
||||
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"]);
|
||||
}
|
||||
|
||||
$activation_coupon = array("l8dd","p43d","k4bu","m4jc","p584","s2bt");
|
||||
$coupon_name = WC()->cart->applied_coupons;
|
||||
$coupon = $coupon_name[0];
|
||||
if (in_array($coupon, $activation_coupon)) {
|
||||
|
||||
$fees = WC()->cart->get_fees();
|
||||
|
||||
foreach ($fees as $key => $fee) {
|
||||
// unset that specific fee from the array
|
||||
if($fees[$key]->name === __( "Setup Fee")) {
|
||||
unset($fees[$key]);
|
||||
if (isset($_SESSION["Activation Fee"]) && !in_array("free-activation", $coupons_val)) {
|
||||
$cartItem = null;
|
||||
foreach (WC()->cart->get_cart() as $i) {
|
||||
$cartItem = $i;
|
||||
}
|
||||
}
|
||||
// set new fee array
|
||||
WC()->cart->fees_api()->set_fees($fees);
|
||||
$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"];
|
||||
@@ -231,32 +232,55 @@ if (isset($_SESSION["Activation Fee"]) && !in_array("free-activation", $coupons_
|
||||
|
||||
});
|
||||
|
||||
add_action( 'woocommerce_cart_calculate_fees', 'add_setup_fees');
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
function add_setup_fees( $cart ) {
|
||||
$activation_coupon = array("l8dd","p43d","k4bu","m4jc","p584","s2bt");
|
||||
$coupon_name = WC()->cart->applied_coupons;
|
||||
$coupon = $coupon_name[0];
|
||||
if (in_array($coupon, $activation_coupon)) {
|
||||
|
||||
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();
|
||||
$pro_coupon = (float)'29.95';
|
||||
$monthlyCosts = (float)$monthlyCosts;
|
||||
$oneTimeCosts = (float)$oneTimeCosts;
|
||||
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'));
|
||||
|
||||
$coupon_title = "Free Activation";
|
||||
$oneTimeCosts = '50.00';
|
||||
$activationFee = 'Programming Fee';
|
||||
$programming_fee = (float)'49.95';
|
||||
WC()->cart->add_fee($activationFee, $programming_fee);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a cart summary based on your current state
|
||||
*
|
||||
@@ -284,6 +308,8 @@ function generateCartSummary($showCheckoutButton = true) {
|
||||
"shippingName",
|
||||
"couponList",
|
||||
"couponTotal",
|
||||
"activationFeeName",
|
||||
"activationFeeAmount",
|
||||
]);
|
||||
|
||||
// starting aggrigate costs
|
||||
@@ -291,7 +317,7 @@ function generateCartSummary($showCheckoutButton = true) {
|
||||
|
||||
$productMonthly = $product["_regular_price"];
|
||||
$oneTimeCostsFee = $product["activation_fee"]; // AKA Setup fee
|
||||
$activationFee = $product["fee_type"];
|
||||
$activationFeeName = $product["fee_type"];
|
||||
$cart = WC()->cart;
|
||||
$cart_contents = $cart->get_cart();
|
||||
foreach ($cart_contents as $cart_item_key => $cart_item):
|
||||
@@ -317,43 +343,45 @@ function generateCartSummary($showCheckoutButton = true) {
|
||||
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') {
|
||||
$discountPrice = ($monthlyCosts - ($monthlyCosts * $scoupon->amount));
|
||||
$discount = $monthlyCosts * $scoupon->amount;
|
||||
$samount = ($scoupon->amount / 100) * number_format($productMonthly,2);
|
||||
$coupon_title = "Coupon";
|
||||
$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') {
|
||||
$samount = $scoupon->amount;
|
||||
$coupon_title = "Coupon";
|
||||
}
|
||||
}
|
||||
|
||||
$activation_coupon = array('l8dd','p43d','k4bu','m4jc','p584','s2bt');
|
||||
$coupon_name = WC()->cart->applied_coupons;
|
||||
$coupon = $coupon_name[0];
|
||||
|
||||
if (in_array($coupon, $activation_coupon)) {
|
||||
WC()->session->set('chosen_shipping_methods', array( 'free_shipping:4' ) );
|
||||
$programming_fee_name = 'Programming Fee';
|
||||
$programming_fee_val = (float)'49.95';
|
||||
$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();
|
||||
$pro_coupon = (float)'29.95';
|
||||
unset($activationFee);
|
||||
$unset_activationfee = (float)50.00;
|
||||
|
||||
if ($samount == 0) {
|
||||
unset($coupon_title);
|
||||
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();
|
||||
@@ -366,15 +394,15 @@ $activation_coupon = array('l8dd','p43d','k4bu','m4jc','p584','s2bt');
|
||||
|
||||
$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';
|
||||
$pro_coupon = (float)'29.95';
|
||||
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;
|
||||
@@ -413,8 +441,6 @@ $protectionPlanPrice = reset($protectionPlan)["price"];
|
||||
$keyLockboxLabel = reset($keyLockbox)["label"];
|
||||
$keyLockboxPrice = reset($keyLockbox)["price"];
|
||||
|
||||
|
||||
|
||||
if (is_iterable($_SESSION["addOns"])) {
|
||||
|
||||
foreach ($_SESSION["addOns"] as $addOn) {
|
||||
@@ -441,8 +467,18 @@ if (is_iterable($_SESSION["addOns"])) {
|
||||
$shipping_methods = WC()->session->get('chosen_shipping_methods');
|
||||
$freeship_name = "Free Shipping";
|
||||
$freeship_discount = WC()->cart->get_coupon_discount_totals();
|
||||
$pro_coupon = (float)'29.95';
|
||||
$total_cart = ($monthlyCosts * 6) + $oneTimeCostsFee + $fallDetectionPrice + $protectionPlanPrice + $keyLockboxPrice + $professional_onetime;
|
||||
$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);
|
||||
@@ -454,21 +490,106 @@ if (is_iterable($_SESSION["addOns"])) {
|
||||
$shipping_methods = WC()->session->get('chosen_shipping_methods');
|
||||
$freeship_name = "Free Shipping";
|
||||
$freeship_discount = WC()->cart->get_coupon_discount_totals();
|
||||
$pro_coupon = (float)'29.95';
|
||||
//$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';
|
||||
}
|
||||
$total_cart = ($monthlyCosts * 12) + $oneTimeCostsFee + $fallDetectionPrice + $protectionPlanPrice + $professional_onetime;
|
||||
|
||||
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,
|
||||
//"addon" => $_SESSION["addOns"],
|
||||
"fallDetectionLabel" => $fallDetectionLabel,
|
||||
"fallDetectionPrice" => $fallDetectionPrice,
|
||||
"protectionPlan" => $protectionPlanLabel,
|
||||
@@ -478,18 +599,20 @@ $fees = WC()->cart->get_fees();
|
||||
"one-time" => $proinstall_label,
|
||||
"pro-one-time" => $professional_onetime,
|
||||
"couponList" => $coupon_title,
|
||||
"couponTotal" => $samount,
|
||||
"couponTotal" => $coupon_amount,
|
||||
"defaultShipping" => $shippingPrice,
|
||||
"shippingName" => $shipping_type,
|
||||
"shipCoupon" => $pro_coupon,
|
||||
"shipCoupon" => $shipping_total,
|
||||
"shipCouponName" => $freeship_name,
|
||||
"totalMonthly" => $monthlyCosts,
|
||||
//"activation_fee" => $oneTimeCosts,
|
||||
"activationFee" => $activationFee,
|
||||
"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"),
|
||||
]));
|
||||
}
|
||||
@@ -557,12 +680,6 @@ $additionalWooFields = [
|
||||
"placeholder" => "Last Name",
|
||||
"required" => true,
|
||||
],
|
||||
"subscriber_gender" => [
|
||||
"type" => "radio",
|
||||
"label" => "Gender",
|
||||
"options" => ["male" => "Male", "female" => "Female"],
|
||||
"required" => true,
|
||||
],
|
||||
"subscriber_address_1" => [
|
||||
"type" => "text",
|
||||
"label" => "",
|
||||
@@ -645,10 +762,6 @@ $additionalWooFields = [
|
||||
"label" => "",
|
||||
"placeholder" => "Phone Number",
|
||||
],
|
||||
"caregiver_authorized" => [
|
||||
"type" => "text",
|
||||
"label" => "Select if this person is authorized by the Care Recipient to create, access and make changes to: (1) the Care Recipient's personal and health information; (2) their caregivers and roles; And (3) the Lifeline account by phone, email, or digital applications offered with your service.",
|
||||
],
|
||||
"card_number" => [
|
||||
"type" => "number",
|
||||
"label" => "Credit Card",
|
||||
@@ -984,6 +1097,7 @@ add_filter('woocommerce_email_order_meta_fields', function ($fields, $sent_to_ad
|
||||
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();
|
||||
@@ -1162,7 +1276,30 @@ function restrict_cart_to_one_item($cart_item_data, $product_id, $variation_id)
|
||||
$woocommerce->cart->empty_cart();
|
||||
}
|
||||
|
||||
// Return the cart item data to add the new item
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user