Feature/TWEB-143 woo order data to sf
This commit is contained in:
108
wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php
Normal file
108
wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: Affiliate Host 'n Post
|
||||||
|
Description: Handles form submissions and integrates with Salesforce and Five9 APIs.
|
||||||
|
Version: 1.0
|
||||||
|
Author: Anthony Volpe
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Function to handle the Salesforce form submission
|
||||||
|
function postsf($data)
|
||||||
|
{
|
||||||
|
$oid = "00D1I000000mJ0Q";
|
||||||
|
$lead_source = "Web";
|
||||||
|
$member_status = "Web response";
|
||||||
|
$campaign_ID = isset($data['campaign_ID']) ? $data['campaign_ID'] : '';
|
||||||
|
|
||||||
|
$cleanPOST = array(
|
||||||
|
'first_name' => stripslashes($data['first-name']),
|
||||||
|
'last_name' => stripslashes($data['last-name']),
|
||||||
|
'phone' => stripslashes($data['phone']),
|
||||||
|
'email' => stripslashes($data['your-email']),
|
||||||
|
'zip' => stripslashes($data['zip']),
|
||||||
|
'Campaign_ID' => $campaign_ID,
|
||||||
|
'oid' => $oid,
|
||||||
|
'lead_source' => $lead_source,
|
||||||
|
'Custom_Field_1__c' => stripslashes($data['subid1']),
|
||||||
|
'Custom_Field_2__c' => stripslashes($data['subid2']),
|
||||||
|
'Custom_Field_3__c' => stripslashes($data['subid3']),
|
||||||
|
'Custom_Field_4__c' => stripslashes($data['subid4']),
|
||||||
|
);
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://webto.salesforce.com/servlet/servlet.WebToLead");
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Added to ensure the response is captured
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$error = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
return "Salesforce Error: $error";
|
||||||
|
} else {
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to handle the Five9 form submission
|
||||||
|
function post59($data) {
|
||||||
|
$Campaign_ID = '701130000026vNy';
|
||||||
|
date_default_timezone_set('America/New_York');
|
||||||
|
$F9Date = date("Y-m-d")."-". date("H:i");
|
||||||
|
$F9domain = "connect america";
|
||||||
|
$F9list = isset($data['callback']) ? $data['callback'] : '';
|
||||||
|
$newphone = preg_replace('/^1|\D/', '', $data['phone']);
|
||||||
|
|
||||||
|
$cleanPOST = array(
|
||||||
|
'first_name' => stripslashes($data['first-name']),
|
||||||
|
'last_name' => stripslashes($data['last-name']),
|
||||||
|
'number1' => $newphone,
|
||||||
|
'F9domain' => $F9domain,
|
||||||
|
'F9list' => $F9list,
|
||||||
|
'salesforce_id' => $Campaign_ID,
|
||||||
|
'Device_6' => '',
|
||||||
|
'WebDialer_Key' => $F9Date,
|
||||||
|
'F9key' => $F9Date,
|
||||||
|
'F9CallASAP' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://api.five9.com/web2campaign/AddToList");
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
$error = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
return "Five9 Error: $error";
|
||||||
|
} else {
|
||||||
|
curl_close($ch);
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REST API endpoint registration
|
||||||
|
add_action('rest_api_init', function () {
|
||||||
|
register_rest_route('affiliates/v1', '/form', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'handle_form_submission',
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Function to handle the form submission and trigger both postsf() and post59()
|
||||||
|
function handle_form_submission($request)
|
||||||
|
{
|
||||||
|
$params = $request->get_params();
|
||||||
|
$response1 = postsf($params);
|
||||||
|
$response2 = post59($params);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'salesforce_response' => $response1,
|
||||||
|
'five9_response' => $response2
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -38,7 +38,6 @@ $linkedin_url = get_field('linkedin_url', 'option');
|
|||||||
$youtube_url = get_field('youtube_url', 'option');
|
$youtube_url = get_field('youtube_url', 'option');
|
||||||
$consumer_phone_number = get_field('consumer_phone_number', 'option');
|
$consumer_phone_number = get_field('consumer_phone_number', 'option');
|
||||||
$business_phone_number = get_field('business_phone_number', 'option');
|
$business_phone_number = get_field('business_phone_number', 'option');
|
||||||
$address = get_field('address', 'option');
|
|
||||||
$copyright_info = get_field('copyright_info', 'option');
|
$copyright_info = get_field('copyright_info', 'option');
|
||||||
$privacy_policy_link = get_field('privacy_policy_link', 'option');
|
$privacy_policy_link = get_field('privacy_policy_link', 'option');
|
||||||
$terms_of_use_link = get_field('terms_of_use_link', 'option');
|
$terms_of_use_link = get_field('terms_of_use_link', 'option');
|
||||||
@@ -47,86 +46,18 @@ $incident_report_link = get_field('incident_report_link', 'option');
|
|||||||
$consumer_disclaimer = get_field('consumer_disclaimer', 'option');
|
$consumer_disclaimer = get_field('consumer_disclaimer', 'option');
|
||||||
$business_disclaimer = get_field('business_disclaimer', 'option');
|
$business_disclaimer = get_field('business_disclaimer', 'option');
|
||||||
$caution_info = get_field('caution_info', 'option');
|
$caution_info = get_field('caution_info', 'option');
|
||||||
$referral_paragraph = get_field('referral_paragraph', 'option');
|
|
||||||
$banner_bottom = get_field('banner_bottom', 'option');
|
$banner_bottom = get_field('banner_bottom', 'option');
|
||||||
$banner_link = get_field('banner_link', 'option');
|
$banner_link = get_field('banner_link', 'option');
|
||||||
$col_1_consumer_menu_title = get_field('col_1_consumer_menu_title', 'option');
|
$col_1_consumer_menu_title = get_field('col_1_consumer_menu_title', 'option');
|
||||||
$col_2_consumer_menu_title = get_field('col_2_consumer_menu_title', 'option');
|
$col_2_consumer_menu_title = get_field('col_2_consumer_menu_title', 'option');
|
||||||
$col_3_consumer_menu_title = get_field('col_3_consumer_menu_title', 'option');
|
$col_3_consumer_menu_title = get_field('col_3_consumer_menu_title', 'option');
|
||||||
$col_4_consumer_menu_title = get_field('col_4_consumer_menu_title', 'option');
|
$col_4_consumer_menu_title = get_field('col_4_consumer_menu_title', 'option');
|
||||||
$col_1_business_menu_title = get_field('col_1_business_menu_title', 'option');
|
|
||||||
$col_2_business_menu_title = get_field('col_2_business_menu_title', 'option');
|
|
||||||
$col_3_business_menu_title = get_field('col_3_business_menu_title', 'option');
|
|
||||||
$col_4_business_menu_title = get_field('col_4_business_menu_title', 'option');
|
|
||||||
$google_link = get_field('google_link', 'option');
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<footer class="site-footer <?php echo $stylesheet; ?>">
|
<footer class="site-footer <?php echo $stylesheet; ?>">
|
||||||
<div class="footer-wrapper">
|
<div class="footer-wrapper">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<?php if( $stylesheet == 'business-brand' ) { ?>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-3">
|
|
||||||
<h3 class="text-uppercase text-white"><?php echo $col_1_business_menu_title; ?></h3>
|
|
||||||
<?php
|
|
||||||
wp_nav_menu(array(
|
|
||||||
'theme_location' => 'col-one-business-menu',
|
|
||||||
'container' => false,
|
|
||||||
'menu_class' => '',
|
|
||||||
'fallback_cb' => '__return_false',
|
|
||||||
'items_wrap' => '<ul id="%1$s" class="footer-nav-list %2$s">%3$s</ul>',
|
|
||||||
'depth' => 2,
|
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
|
||||||
));
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-3">
|
|
||||||
<h3 class="text-uppercase text-white"><?php echo $col_2_business_menu_title; ?></h3>
|
|
||||||
<?php
|
|
||||||
wp_nav_menu(array(
|
|
||||||
'theme_location' => 'col-two-business-menu',
|
|
||||||
'container' => false,
|
|
||||||
'menu_class' => '',
|
|
||||||
'fallback_cb' => '__return_false',
|
|
||||||
'items_wrap' => '<ul id="%1$s" class="footer-nav-list %2$s">%3$s</ul>',
|
|
||||||
'depth' => 2,
|
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
|
||||||
));
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-3">
|
|
||||||
<h3 class="text-uppercase text-white"><?php echo $col_3_business_menu_title; ?></h3>
|
|
||||||
<?php
|
|
||||||
wp_nav_menu(array(
|
|
||||||
'theme_location' => 'col-three-business-menu',
|
|
||||||
'container' => false,
|
|
||||||
'menu_class' => '',
|
|
||||||
'fallback_cb' => '__return_false',
|
|
||||||
'items_wrap' => '<ul id="%1$s" class="footer-nav-list %2$s">%3$s</ul>',
|
|
||||||
'depth' => 2,
|
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
|
||||||
));
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-3">
|
|
||||||
<h3 class="text-uppercase text-white"><?php echo $col_4_business_menu_title; ?></h3>
|
|
||||||
<?php if( isset($referral_paragraph) ) : ?>
|
|
||||||
<p class="text-white"><?php echo $referral_paragraph; ?></p>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php
|
|
||||||
wp_nav_menu(array(
|
|
||||||
'theme_location' => 'col-four-business-menu',
|
|
||||||
'container' => false,
|
|
||||||
'menu_class' => '',
|
|
||||||
'fallback_cb' => '__return_false',
|
|
||||||
'items_wrap' => '<ul id="%1$s" class="footer-nav-list %2$s">%3$s</ul>',
|
|
||||||
'depth' => 2,
|
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
|
||||||
));
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php } else { ?>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<h3 class="text-uppercase text-white"><?php echo $col_1_consumer_menu_title; ?></h3>
|
<h3 class="text-uppercase text-white"><?php echo $col_1_consumer_menu_title; ?></h3>
|
||||||
@@ -185,7 +116,6 @@ $google_link = get_field('google_link', 'option');
|
|||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
|
||||||
<div class="row d-flex justify-content-center align-items-center p-4">
|
<div class="row d-flex justify-content-center align-items-center p-4">
|
||||||
<div class="col-lg-5 col-xl-6">
|
<div class="col-lg-5 col-xl-6">
|
||||||
<img class="img-fluid footer-logo" src="<?php echo $company_logo['url']; ?>" />
|
<img class="img-fluid footer-logo" src="<?php echo $company_logo['url']; ?>" />
|
||||||
@@ -228,7 +158,6 @@ $google_link = get_field('google_link', 'option');
|
|||||||
<a class="text-decoration-none text-white" href="<?php echo $incident_report_link['url']; ?>">Submit Incident Report</a><span class="px-2"></span>
|
<a class="text-decoration-none text-white" href="<?php echo $incident_report_link['url']; ?>">Submit Incident Report</a><span class="px-2"></span>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
<p class="text-white text-center"><a href="<?php echo $google_link; ?>" target="_blank" aria-label="Link opens in a new tab" style="" class="text-center text-decoration-none text-wrap text-white"><?php echo $address; ?></a></p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row w-100 p-2">
|
<div class="row w-100 p-2">
|
||||||
@@ -242,11 +171,7 @@ $google_link = get_field('google_link', 'option');
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row pb-4">
|
<div class="row pb-4">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<?php if( $stylesheet == 'business-brand' ) { ?>
|
|
||||||
<?php echo $business_disclaimer; ?>
|
|
||||||
<?php } else { ?>
|
|
||||||
<?php echo $consumer_disclaimer; ?>
|
<?php echo $consumer_disclaimer; ?>
|
||||||
<?php } ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -273,8 +198,6 @@ $google_link = get_field('google_link', 'option');
|
|||||||
</a>
|
</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<i class="fa fa-window-close banner-bottom-close" aria-hidden="true"></i>
|
<i class="fa fa-window-close banner-bottom-close" aria-hidden="true"></i>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,98 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
add_action( 'gform_after_submission_1', 'post_to_salesforce_and_five9', 10, 2 );
|
||||||
|
function post_to_salesforce_and_five9( $entry, $form ) {
|
||||||
|
post_to_salesforce( $entry, $form );
|
||||||
|
postFiveNine( $entry, $form );
|
||||||
|
}
|
||||||
|
|
||||||
|
function post_to_salesforce( $entry, $form ) {
|
||||||
|
$salesforceEnvironment = get_option('select-environment');
|
||||||
|
|
||||||
|
if ($salesforceEnvironment == 'full') {
|
||||||
|
$Campaign_ID = '7011I000000dF9n';
|
||||||
|
$sfdc_oid = '00DDh0000009Umu';
|
||||||
|
$webtolead_url = 'https://test.salesforce.com/servlet/servlet.WebToLead';
|
||||||
|
} else {
|
||||||
|
$Campaign_ID = '7011I000000dDwA';
|
||||||
|
$sfdc_oid = '00D1I000000mJ0Q';
|
||||||
|
$webtolead_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead';
|
||||||
|
}
|
||||||
|
|
||||||
|
$cleanPOST = array(
|
||||||
|
'first_name' => rgar( $entry, '1.3' ),
|
||||||
|
'last_name' => rgar( $entry, '1.6' ),
|
||||||
|
'phone' => rgar( $entry, '3' ),
|
||||||
|
'email' => rgar( $entry, '4' ),
|
||||||
|
'lead_source' => 'Web',
|
||||||
|
'oid' => $sfdc_oid,
|
||||||
|
'Campaign_ID' => $Campaign_ID,
|
||||||
|
'member_status' => 'Web response',
|
||||||
|
'Inquiring_for__c' => rgar( $entry, '5' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $webtolead_url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
$error_msg = curl_error($ch);
|
||||||
|
//error_log('Salesforce Web-to-Lead Error: ' . $error_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to send data to Five9
|
||||||
|
function postFiveNine( $entry, $form ) {
|
||||||
|
$Campaign_ID = '701130000026vNy';
|
||||||
|
$F9list = "Web Form Submissions H";
|
||||||
|
$F9domain = "connect america";
|
||||||
|
$permalink = getenv('HTTP_REFERER');
|
||||||
|
$title = get_permalink(url_to_postid($permalink));
|
||||||
|
date_default_timezone_set('America/New_York');
|
||||||
|
$F9Date = date("Y-m-d") . "-" . date("H:i");
|
||||||
|
$newphone = preg_replace('/^1|\D/', '', rgar($entry, '3'));
|
||||||
|
|
||||||
|
$cleanPOST = array(
|
||||||
|
'first_name' => sanitize_text_field(rgar($entry, '1.3')),
|
||||||
|
'last_name' => sanitize_text_field(rgar($entry, '1.6')),
|
||||||
|
'number1' => $newphone,
|
||||||
|
'F9domain' => $F9domain,
|
||||||
|
'F9list' => $F9list,
|
||||||
|
'salesforce_id' => $Campaign_ID,
|
||||||
|
'Device_6' => $title,
|
||||||
|
'WebDialer_Key' => $F9Date,
|
||||||
|
'F9key' => WebDialer_Key,
|
||||||
|
'F9CallASAP' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://api.five9.com/web2campaign/AddToList");
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
$error_msg = curl_error($ch);
|
||||||
|
//error_log('Five9 API Error: ' . $error_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// To complete at at later date
|
// To complete at at later date
|
||||||
//add_action('wp_enqueue_scripts', 'enqueue_google_maps_autocomplete');
|
//add_action('wp_enqueue_scripts', 'enqueue_google_maps_autocomplete');
|
||||||
|
|
||||||
|
include_once(get_template_directory() . '/helpers/SecuredContent.php');
|
||||||
|
|
||||||
function enqueue_google_maps_autocomplete() {
|
function enqueue_google_maps_autocomplete() {
|
||||||
wp_enqueue_script( 'auto-complete', get_template_directory_uri().'/vendor/google/auto-complete.js');
|
wp_enqueue_script( 'auto-complete', get_template_directory_uri().'/vendor/google/auto-complete.js');
|
||||||
}
|
}
|
||||||
@@ -386,6 +476,9 @@ $protectionPlan = array_filter($_SESSION["addOns"], function($item) {
|
|||||||
$keyLockbox = array_filter($_SESSION["addOns"], function($item) {
|
$keyLockbox = array_filter($_SESSION["addOns"], function($item) {
|
||||||
return $item["label"] === "Key Lockbox";
|
return $item["label"] === "Key Lockbox";
|
||||||
});
|
});
|
||||||
|
$keyLockbox = array_filter($_SESSION["addOns"], function($item) {
|
||||||
|
return $item["label"] === "Lockbox";
|
||||||
|
});
|
||||||
|
|
||||||
// Store label and price in individual variables
|
// Store label and price in individual variables
|
||||||
$fallDetectionLabel = reset($fallDetection)["label"];
|
$fallDetectionLabel = reset($fallDetection)["label"];
|
||||||
@@ -469,6 +562,7 @@ if (is_iterable($_SESSION["addOns"])) {
|
|||||||
// addons salesforce ID
|
// addons salesforce ID
|
||||||
$falldetection_sfid = $_SESSION["addOns"]["Fall Detection"]["salesforce_id"];;
|
$falldetection_sfid = $_SESSION["addOns"]["Fall Detection"]["salesforce_id"];;
|
||||||
$protectionplan_sfid = $_SESSION["addOns"]["Protection Plan"]["salesforce_id"];
|
$protectionplan_sfid = $_SESSION["addOns"]["Protection Plan"]["salesforce_id"];
|
||||||
|
$lockbox_sfid = $_SESSION["addOns"]["Lockbox"]["salesforce_id"];
|
||||||
|
|
||||||
// Method to access protected property
|
// Method to access protected property
|
||||||
function get_protected_property($object, $property) {
|
function get_protected_property($object, $property) {
|
||||||
@@ -477,14 +571,20 @@ function get_protected_property($object, $property) {
|
|||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
return $property->getValue($object);
|
return $property->getValue($object);
|
||||||
}
|
}
|
||||||
|
//var_dump($falldetection_sfid);
|
||||||
|
//var_dump($protectionplan_sfid);
|
||||||
|
//var_dump($_SESSION["addOns"]);
|
||||||
|
//var_dump($lockbox_sfid);
|
||||||
|
|
||||||
// Get the SKU from the protected parent_data property
|
// Get the SKU from the protected parent_data property
|
||||||
$parent_data = get_protected_property($cart_item['data'], 'parent_data');
|
//$parent_data = get_protected_property($cart_item['data'], 'parent_data');
|
||||||
$sku = $parent_data['sku']; // Salesforce ProductID
|
//$sku = $parent_data['sku']; // Salesforce ProductID
|
||||||
$rate_plan_sfid = $cart_item['variation']['attribute_rate-plan-sfid']; // Product rate plan salesforce ID
|
$rate_plan_sfid = $cart_item['variation']['attribute_rate-plan-sfid']; // Product rate plan salesforce ID
|
||||||
$product_id = $cart_item['product_id'];
|
$product_id = $cart_item['product_id'];
|
||||||
$accessories = get_field( 'accessories', $product_id );
|
$accessories = get_field( 'accessories', $product_id );
|
||||||
|
|
||||||
|
//var_dump($rate_plan_sfid);
|
||||||
|
|
||||||
foreach ($accessories as $accessory) {
|
foreach ($accessories as $accessory) {
|
||||||
// Sanitize the accessory to create a valid PHP variable
|
// Sanitize the accessory to create a valid PHP variable
|
||||||
$sanitized_name = strtolower(str_replace(' ', '_', $accessory["accessory_name"]));
|
$sanitized_name = strtolower(str_replace(' ', '_', $accessory["accessory_name"]));
|
||||||
@@ -573,6 +673,10 @@ if ($is_sixforsix_applied || $is_fiveoff_applied) {
|
|||||||
$coupon_amount = $coupon->amount;
|
$coupon_amount = $coupon->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cart_items = WC()->cart->get_cart();
|
||||||
|
//var_dump($cart_items);
|
||||||
|
|
||||||
|
|
||||||
return site()->render("cart_summary", array_merge($product, [
|
return site()->render("cart_summary", array_merge($product, [
|
||||||
"variable_price" => $variable_price,
|
"variable_price" => $variable_price,
|
||||||
"addonPrice" => $addon_price,
|
"addonPrice" => $addon_price,
|
||||||
@@ -1067,7 +1171,7 @@ add_filter('woocommerce_email_order_meta_fields', function ($fields, $sent_to_ad
|
|||||||
foreach ($additionalWooFields as $key => $value) {
|
foreach ($additionalWooFields as $key => $value) {
|
||||||
$fields[$key] = [
|
$fields[$key] = [
|
||||||
'label' => strlen($value["label"]) ? $value["label"] : $value["placeholder"],
|
'label' => strlen($value["label"]) ? $value["label"] : $value["placeholder"],
|
||||||
'value' => get_post_meta($order->id, $key, true),
|
'value' => get_post_meta($order->get_id(), $key, true), // Corrected line
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1080,71 +1184,405 @@ add_filter('woocommerce_email_order_meta_fields', function ($fields, $sent_to_ad
|
|||||||
return $fields;
|
return $fields;
|
||||||
}, 10, 3);
|
}, 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
// Save the card number during checkout
|
||||||
|
//add_action('woocommerce_checkout_update_order_meta', 'save_card_number_to_order_meta');
|
||||||
|
//function save_card_number_to_order_meta($order_id) {
|
||||||
|
// if (isset($_POST['card_number']) && !empty($_POST['card_number'])) {
|
||||||
|
// $card_number = sanitize_text_field($_POST['card_number']);
|
||||||
|
// update_post_meta($order_id, '_card_number', $card_number);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
add_action('woocommerce_checkout_update_order_meta', 'save_card_details_to_order_meta');
|
||||||
|
function save_card_details_to_order_meta($order_id) {
|
||||||
|
// Save the card number
|
||||||
|
if (isset($_POST['card_number']) && !empty($_POST['card_number'])) {
|
||||||
|
$card_number = sanitize_text_field($_POST['card_number']);
|
||||||
|
update_post_meta($order_id, '_card_number', $card_number);
|
||||||
|
|
||||||
|
// Determine card type based on the card number
|
||||||
|
$card_type = detect_card_type($card_number);
|
||||||
|
if ($card_type) {
|
||||||
|
update_post_meta($order_id, '_card_type', $card_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the expiration month
|
||||||
|
if (isset($_POST['expiration_month']) && !empty($_POST['expiration_month'])) {
|
||||||
|
$expiration_month = sanitize_text_field($_POST['expiration_month']);
|
||||||
|
update_post_meta($order_id, '_expiration_month', $expiration_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the expiration year
|
||||||
|
if (isset($_POST['expiration_year']) && !empty($_POST['expiration_year'])) {
|
||||||
|
$expiration_year = sanitize_text_field($_POST['expiration_year']);
|
||||||
|
update_post_meta($order_id, '_expiration_year', $expiration_year);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to detect card type based on the card number.
|
||||||
|
*/
|
||||||
|
function detect_card_type($number) {
|
||||||
|
$number = preg_replace('/\D/', '', $number); // Remove all non-digit characters
|
||||||
|
|
||||||
|
// Regex patterns for card types
|
||||||
|
$patterns = [
|
||||||
|
'Visa' => '/^4[0-9]{12}(?:[0-9]{3})?$/',
|
||||||
|
'MasterCard' => '/^5[1-5][0-9]{14}$/',
|
||||||
|
'American Express' => '/^3[47][0-9]{13}$/',
|
||||||
|
'Discover' => '/^6(?:011|5[0-9]{2})[0-9]{12}$/'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($patterns as $type => $pattern) {
|
||||||
|
if (preg_match($pattern, $number)) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return null if no patterns match
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Hook into woocommerce_thankyou action
|
||||||
add_action('woocommerce_thankyou', function ($order_id) {
|
add_action('woocommerce_thankyou', function ($order_id) {
|
||||||
|
// Get and sanitize card number from POST data
|
||||||
|
$card_number = get_post_meta($order_id, '_card_number', true);
|
||||||
|
error_log("Card Number: " . $card_number);
|
||||||
|
// Fetch the order
|
||||||
$order = wc_get_order($order_id);
|
$order = wc_get_order($order_id);
|
||||||
//wc_get_template( 'order/order-details-customer.php', array('order' => $order ));
|
|
||||||
|
|
||||||
|
// Collect order details for Salesforce and rendering (this remains the same)
|
||||||
|
$order_data = [];
|
||||||
foreach ($order->get_items() as $item) {
|
foreach ($order->get_items() as $item) {
|
||||||
$item_data = $item->get_data();
|
$item_data = $item->get_data();
|
||||||
$formatted_meta_data = $item->get_formatted_meta_data('_', true);
|
$formatted_meta_data = $item->get_formatted_meta_data('_', true);
|
||||||
|
$order_data['items'][] = [
|
||||||
|
'name' => $item->get_name(),
|
||||||
|
'product_id' => $item->get_product_id(),
|
||||||
|
'quantity' => $item->get_quantity(),
|
||||||
|
'subtotal' => $item->get_subtotal(),
|
||||||
|
'total' => $item->get_total(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $order->get_fees() as $fees )
|
$order_products = [];
|
||||||
$coupon = new WC_Coupon( $coupon_code );
|
foreach ($order->get_items() as $item) {
|
||||||
$product_subtotal = $order->subtotal; // 29.95
|
$product = $item->get_product(); // Get the WC_Product object
|
||||||
$order_total = (float)$order->get_total();
|
$product_id = $product->get_id();
|
||||||
$shipping = (float)$order->discount_total;
|
$product_sku = $product->get_sku();
|
||||||
$coupon_total = (float)$coupon->amount; // $50.00
|
$quantity = $item->get_quantity();
|
||||||
|
|
||||||
|
// Initialize variables
|
||||||
|
$rate_plan_id = null;
|
||||||
|
$attributes = [];
|
||||||
|
|
||||||
|
// Check if the product is a variation
|
||||||
|
if ($product->is_type('variation')) {
|
||||||
|
$parent_id = $product->get_parent_id(); // Get the parent variable product ID
|
||||||
|
$attributes = $product->get_attributes(); // Get variation attributes
|
||||||
|
var_dump($attributes['rate-plan-sfid']);
|
||||||
|
// Get Rate Plan ID custom field for the variation
|
||||||
|
$rate_plan_id = get_post_meta($product_id, 'rate_plan_id', true); // Adjust if needed
|
||||||
|
|
||||||
|
// Optional: Include additional variation details
|
||||||
|
$variation_label = implode(', ', $attributes);
|
||||||
|
} else {
|
||||||
|
// For non-variation products, still fetch Rate Plan ID if it exists
|
||||||
|
$rate_plan_id = get_post_meta($product_id, 'rate_plan_id', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fees_total = 0;
|
||||||
|
foreach ($order->get_fees() as $fees) {
|
||||||
|
$order_data['fees'][] = [
|
||||||
|
'name' => $fees->get_name(),
|
||||||
|
'amount' => $fees->get_amount(),
|
||||||
|
];
|
||||||
|
$fees_total += $fees->get_amount();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($order->get_coupon_codes() as $coupon_code) {
|
foreach ($order->get_coupon_codes() as $coupon_code) {
|
||||||
$coupon = new WC_Coupon($coupon_code);
|
$coupon = new WC_Coupon($coupon_code);
|
||||||
$count = $coupon->get_usage_count();
|
$order_data['coupons'][] = [
|
||||||
$limit = $coupon->get_usage_limit_per_user();
|
'code' => $coupon_code,
|
||||||
|
'discount_amount' => $coupon->get_amount(),
|
||||||
if ( ! empty ( $count ) && ! empty ( $limit ) ) {
|
'remaining_usage' => ($coupon->get_usage_limit_per_user() - $coupon->get_usage_count())
|
||||||
$remaining = $limit - $count;
|
];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order->shipping_total == 0) {
|
// Shipping and Coupon Amount Calculation
|
||||||
$shipping_label = 'Shipping';
|
if ($order->get_shipping_total() == 0) {
|
||||||
$freeshipping_cost = 'Free';
|
$shipping_label = 'Free Shipping';
|
||||||
|
$shipping_cost = 0;
|
||||||
} else {
|
} else {
|
||||||
$shipping_label = 'Shipping';
|
$shipping_label = 'Shipping';
|
||||||
$shipping_cost = $order->shipping_total;
|
$shipping_cost = $order->get_shipping_total();
|
||||||
}
|
}
|
||||||
|
|
||||||
$coupon_amount = $order->discount_total;
|
$order_data['shipping'] = [
|
||||||
if ($coupon_amount == 0) {
|
'label' => $shipping_label,
|
||||||
unset($coupon_code);
|
'cost' => $shipping_cost
|
||||||
|
];
|
||||||
|
|
||||||
|
// Total and Subtotal Data
|
||||||
|
$order_total = (float)$order->get_total();
|
||||||
|
$order_subtotal = (float)$order->get_subtotal();
|
||||||
|
$coupon_total = (float)$order->get_discount_total();
|
||||||
|
|
||||||
|
$order_data['totals'] = [
|
||||||
|
'subtotal' => $order_subtotal,
|
||||||
|
'total' => $order_total,
|
||||||
|
'discount' => $coupon_total
|
||||||
|
];
|
||||||
|
|
||||||
|
// Send the order data to Salesforce with encryption
|
||||||
|
$request_payload = createOrderRequest($order, $card_number);
|
||||||
|
|
||||||
|
// Create a new instance of the SalesforceSync class and send the request
|
||||||
|
$sf = new SalesforceSync(SalesforceSync::kACTION_ORDER_CREATE, $request_payload);
|
||||||
|
// Send the request and log the response
|
||||||
|
$response = $sf->sendRequest();
|
||||||
|
|
||||||
|
// Log the raw response from Salesforce for debugging
|
||||||
|
error_log('Salesforce Response (Raw): ' . print_r($response, true));
|
||||||
|
|
||||||
|
// Decode the response (assuming it is double-encoded JSON)
|
||||||
|
$decoded_response = json_decode(json_decode($response));
|
||||||
|
|
||||||
|
// Check if there are errors in the decoded response and log them
|
||||||
|
if (isset($decoded_response->ErrorList)) {
|
||||||
|
$error_response = serialize($decoded_response->ErrorList);
|
||||||
|
error_log('Salesforce API Error: ' . $error_response);
|
||||||
|
} else {
|
||||||
|
// Log the successful response if no errors are present
|
||||||
|
error_log('Salesforce Response (Decoded): ' . print_r($decoded_response, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the order details on the thank-you page
|
||||||
echo site()->render("thank-you-order-details", [
|
echo site()->render("thank-you-order-details", [
|
||||||
"setupFeePrice" => $fees->get_amount(),
|
"setupFeePrice" => $fees_total,
|
||||||
"setupFeeName" => $fees->get_name(),
|
"setupFeeName" => isset($order_data['fees'][0]['name']) ? $order_data['fees'][0]['name'] : '',
|
||||||
"couponCode" => $coupon_code,
|
"couponCode" => isset($order_data['coupons'][0]['code']) ? $order_data['coupons'][0]['code'] : '',
|
||||||
"couponAmount" => $coupon_amount,
|
"couponAmount" => $coupon_total,
|
||||||
"monthlyFee" => $order->subtotal,
|
"monthlyFee" => $order_subtotal,
|
||||||
"shippingLabel" => $shipping_label,
|
"shippingLabel" => $shipping_label,
|
||||||
"shippingCost" => $shipping_cost,
|
"shippingCost" => $shipping_cost,
|
||||||
"freeshippingCost" => $freeshipping_cost,
|
"freeshippingCost" => ($shipping_cost == 0) ? 'Free' : '',
|
||||||
"items" => array_map(function ($i) {
|
"items" => array_map(function ($i) {
|
||||||
return [
|
return [
|
||||||
"name" => $i->get_name(),
|
"name" => $i['name'],
|
||||||
"image" => $i->get_product()->get_image([100, 100]),
|
"image" => wc_get_product($i['product_id'])->get_image([100, 100]), // Get product image
|
||||||
];
|
];
|
||||||
}, $order->get_items()),
|
}, $order_data['items']),
|
||||||
"total" => $order->get_total(),
|
"total" => $order_total,
|
||||||
"fees" => array_map(function ($f) {
|
"fees" => $order_data['fees']
|
||||||
return [
|
|
||||||
"name" => $f->get_name(),
|
|
||||||
"amount" => $f->get_amount(),
|
|
||||||
];
|
|
||||||
}, $order->get_fees()),
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve accessories data for a product.
|
||||||
|
*/
|
||||||
|
function getProductAccessories($product_id) {
|
||||||
|
$accessories = get_field('accessories', $product_id);
|
||||||
|
$formatted_accessories = [];
|
||||||
|
|
||||||
|
if (!empty($accessories)) {
|
||||||
|
foreach ($accessories as $accessory) {
|
||||||
|
$formatted_accessories[] = [
|
||||||
|
"AccessoryID" => $accessory['salesforce_id'],
|
||||||
|
"Quantity" => 1,
|
||||||
|
"Price" => $accessory['price']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formatted_accessories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the payload for the order to send to Salesforce.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Creates the payload for the order to send to Salesforce.
|
||||||
|
*/
|
||||||
|
function createOrderRequest($order) {
|
||||||
|
// Retrieve card type from order meta
|
||||||
|
$card_type = get_post_meta($order->get_id(), '_card_type', true);
|
||||||
|
|
||||||
|
// Retrieve other payment information from the order if needed
|
||||||
|
$card_number = get_post_meta($order->get_id(), '_card_number', true);
|
||||||
|
$expiration_month = get_post_meta($order->get_id(), '_expiration_month', true);
|
||||||
|
$expiration_year = get_post_meta($order->get_id(), '_expiration_year', true);
|
||||||
|
|
||||||
|
// Create the expiration date in the required format (e.g., "MM/YYYY")
|
||||||
|
$expiration_date = sprintf('%02d/%s', $expiration_month, $expiration_year);
|
||||||
|
|
||||||
|
// Generate the request header
|
||||||
|
$header = createRequestHeader();
|
||||||
|
|
||||||
|
// Get billing and shipping information from the order
|
||||||
|
$billing = $order->get_address('billing');
|
||||||
|
$shipping = $order->get_address('shipping');
|
||||||
|
$payment_type = "Credit Card"; // Assuming credit card
|
||||||
|
|
||||||
|
// Format phone number (example: XXX-XXX-XXXX)
|
||||||
|
$billing_phone = preg_replace('/(\d{3})(\d{3})(\d{4})/', '$1-$2-$3', $billing['phone']);
|
||||||
|
$shipping_phone = !empty($shipping['phone']) ? preg_replace('/(\d{3})(\d{3})(\d{4})/', '$1-$2-$3', $shipping['phone']) : $billing_phone;
|
||||||
|
|
||||||
|
// Prepare product items and accessories
|
||||||
|
$order_products = [];
|
||||||
|
foreach ($order->get_items() as $item) {
|
||||||
|
$product = $item->get_product(); // Get the WC_Product object
|
||||||
|
$product_id = $product->get_id();
|
||||||
|
$product_sku = $product->get_sku();
|
||||||
|
$quantity = $item->get_quantity();
|
||||||
|
|
||||||
|
// Initialize variables
|
||||||
|
$rate_plan_id = null;
|
||||||
|
$attributes = [];
|
||||||
|
|
||||||
|
$parent_id = $product->get_parent_id(); // Get the parent variable product ID
|
||||||
|
$attributes = $product->get_attributes(); // Get variation attributes
|
||||||
|
|
||||||
|
// Get Rate Plan ID custom field for the variation
|
||||||
|
$rate_plan_id = get_post_meta($product_id, 'rate_plan_id', true); // Adjust if needed
|
||||||
|
|
||||||
|
// Optional: Include additional variation details
|
||||||
|
$variation_label = implode(', ', $attributes);
|
||||||
|
|
||||||
|
// Fetch accessories related to this product
|
||||||
|
$accessories = getProductAccessories($item->get_product_id());
|
||||||
|
|
||||||
|
error_log( print_r($accessories, true) );
|
||||||
|
// Add variation or product details to the order products array
|
||||||
|
$order_products[] = [
|
||||||
|
'ProductID' => $product_sku,
|
||||||
|
'Quantity' => $item->get_quantity(),
|
||||||
|
'RatePlanID' => $attributes['rate-plan-sfid'],
|
||||||
|
'Accessories' => $accessories,
|
||||||
|
'PromotionID' => $promotion_id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the payload structure
|
||||||
|
$orderRequest = [
|
||||||
|
"RequestHeader" => $header,
|
||||||
|
"RequestBody" => [
|
||||||
|
"CustomerFirstName" => $billing['first_name'],
|
||||||
|
"CustomerLastName" => $billing['last_name'],
|
||||||
|
"CustomerEmail" => $billing['email'],
|
||||||
|
"CustomerPhoneNumber" => $billing_phone,
|
||||||
|
"GCLID" => "", // Add Google Click ID if available
|
||||||
|
"UserExperience" => null, // Optional field
|
||||||
|
"CustomField1" => "", // Add if needed
|
||||||
|
"CustomField2" => "", // Add if needed
|
||||||
|
"CustomField3" => "", // Add if needed
|
||||||
|
"CustomField4" => "", // Add if needed
|
||||||
|
"MarketingCampaign" => "ecom campaign", // Set the campaign name
|
||||||
|
"ShippingID" => "a4t3s000000pYVVAA2", // Replace with dynamic ShippingID if needed
|
||||||
|
"PaymentInformation" => [
|
||||||
|
"PaymentType" => $payment_type,
|
||||||
|
"CardholderName" => $billing['first_name'] . ' ' . $billing['last_name'],
|
||||||
|
"CardType" => $card_type, // Use the card type retrieved from meta
|
||||||
|
"CardNumber" => "XXXXXXXXXXXXXXXX", // Masked card number
|
||||||
|
"ExpirationDate" => $expiration_date // Use the formatted expiration date
|
||||||
|
],
|
||||||
|
"ShippingInformation" => [
|
||||||
|
"FirstName" => $shipping['first_name'],
|
||||||
|
"LastName" => $shipping['last_name'],
|
||||||
|
"Phone" => $shipping_phone,
|
||||||
|
"Street1" => $shipping['address_1'],
|
||||||
|
"Street2" => $shipping['address_2'],
|
||||||
|
"City" => $shipping['city'],
|
||||||
|
"State" => $shipping['state'],
|
||||||
|
"PostalCode" => $shipping['postcode'],
|
||||||
|
"Country" => $shipping['country'] == 'US' ? 'United States' : $shipping['country']
|
||||||
|
],
|
||||||
|
"BillingInformation" => [
|
||||||
|
"FirstName" => $billing['first_name'],
|
||||||
|
"LastName" => $billing['last_name'],
|
||||||
|
"Phone" => $billing_phone,
|
||||||
|
"Street1" => $billing['address_1'],
|
||||||
|
"Street2" => $billing['address_2'],
|
||||||
|
"City" => $billing['city'],
|
||||||
|
"State" => $billing['state'],
|
||||||
|
"PostalCode" => $billing['postcode'],
|
||||||
|
"Country" => $billing['country'] == 'US' ? 'United States' : $billing['country']
|
||||||
|
],
|
||||||
|
"OrderProducts" => $order_products
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $orderRequest; // Return the raw PHP array, not encoded
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a request header with a unique ID.
|
||||||
|
*/
|
||||||
|
function createRequestHeader() {
|
||||||
|
return [
|
||||||
|
"RequestID" => "Request_" . microtime(true) // Unique request ID
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!class_exists("SalesforceSync")) {
|
||||||
|
class SalesforceSync {
|
||||||
|
|
||||||
|
const kACTION_ORDER_CREATE = "CreateOrder";
|
||||||
|
const kAPPEND_URL = "?brand=MedicalAlert"; // Append brand as a query parameter
|
||||||
|
|
||||||
|
private $url;
|
||||||
|
private $content;
|
||||||
|
private $method;
|
||||||
|
|
||||||
|
public function __construct($action, $content, $method = "POST") {
|
||||||
|
// Appending ?brand=MedicalAlert to the URL
|
||||||
|
$environment_url = get_option('id_api_salesforce', true);
|
||||||
|
$this->url = "{$environment_url}/{$action}" . self::kAPPEND_URL;
|
||||||
|
$this->content = $content;
|
||||||
|
$this->method = $method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendRequest() {
|
||||||
|
$crypto = new SecuredContent();
|
||||||
|
$encoded_content = json_encode($crypto->encode_content(json_encode($this->content)));
|
||||||
|
|
||||||
|
$request = curl_init($this->url);
|
||||||
|
curl_setopt($request, CURLOPT_CUSTOMREQUEST, $this->method);
|
||||||
|
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($request, CURLOPT_POSTFIELDS, $encoded_content);
|
||||||
|
curl_setopt($request, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Content-Length: ' . strlen($encoded_content),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Execute the request and retrieve the response
|
||||||
|
$response = curl_exec($request);
|
||||||
|
curl_close($request);
|
||||||
|
|
||||||
|
// Decode the encrypted response
|
||||||
|
return $crypto->decode_content($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure
|
* Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure
|
||||||
*
|
*
|
||||||
@@ -1213,7 +1651,7 @@ function gtm_output() { ?>
|
|||||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||||
})(window,document,'script','dataLayer','GTM-K438P59');</script>
|
})(window,document,'script','dataLayer','GTM-MJH5WQQ');</script>
|
||||||
<!-- End Google Tag Manager -->
|
<!-- End Google Tag Manager -->
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@@ -1221,7 +1659,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|||||||
|
|
||||||
function gtm_noscript_output() { ?>
|
function gtm_noscript_output() { ?>
|
||||||
<!-- Google Tag Manager (noscript) -->
|
<!-- Google Tag Manager (noscript) -->
|
||||||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-K438P59"
|
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MJH5WQQ"
|
||||||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||||
<!-- End Google Tag Manager (noscript) -->
|
<!-- End Google Tag Manager (noscript) -->
|
||||||
|
|
||||||
@@ -1306,3 +1744,5 @@ function shipping_methods_additional_custom_field( $settings ) {
|
|||||||
);
|
);
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,14 +28,7 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
$company_logo = get_field('company_logo', 'option');
|
$company_logo = get_field('company_logo', 'option');
|
||||||
$login_icon = get_field('login_icon', 'option');
|
|
||||||
$consumer_login_link = get_field('consumer_login_link', 'option');
|
|
||||||
$business_login_link = get_field('business_login_link', 'option');
|
|
||||||
$cart_icon = get_field('cart_icon', 'option');
|
|
||||||
$cart_link = get_field('cart_link', 'option');
|
|
||||||
$search_icon = get_field('search_icon', 'option');
|
|
||||||
$consumer_phone_number = get_field('consumer_phone_number', 'option');
|
$consumer_phone_number = get_field('consumer_phone_number', 'option');
|
||||||
$business_phone_number = get_field('business_phone_number', 'option');
|
|
||||||
$stylesheet = get_field('style_sheet');
|
$stylesheet = get_field('style_sheet');
|
||||||
|
|
||||||
// default to consumer brand if we don't have the ACF option for the current page
|
// default to consumer brand if we don't have the ACF option for the current page
|
||||||
@@ -48,57 +41,20 @@
|
|||||||
<div class="bg-light top-menu">
|
<div class="bg-light top-menu">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-end align-items-center d-none d-md-flex top-bar">
|
<div class="row justify-content-end align-items-center d-none d-md-flex top-bar">
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<div class="col col-lg-4 d-flex justify-content-center">
|
|
||||||
<a class="text-decoration-none text-nowrap" href="/business/">Healthcare and Senior Living</a>
|
|
||||||
</div>
|
|
||||||
<?php else : ?>
|
|
||||||
<div class="col col-lg-3 d-flex justify-content-center">
|
|
||||||
<a class="text-decoration-none text-nowrap text-right" href="/">For Consumers</a>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
<!-- <div class="col col-lg-1 d-flex justify-content-end">
|
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<a class="text-decoration-none text-nowrap" href="<?php echo $consumer_login_link['url']; ?>" target="_blank" aria-label="Link opens in a new tab"><i class="bi bi-person-circle" aria-hidden="true"></i> Login</a>
|
|
||||||
<?php else : ?>
|
|
||||||
<a class="text-decoration-none text-nowrap" href="<?php echo $business_login_link['url']; ?>" target="_blank" aria-label="Link opens in a new tab"><i class="bi bi-person-circle" aria-hidden="true"></i> Login</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div> -->
|
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<!-- <div class="col col-lg-1 d-flex justify-content-end">
|
|
||||||
<?php if (is_array($cart_link) && isset($cart_link['url'])) {?>
|
|
||||||
<a class="text-decoration-none text-nowrap" href="<?php echo $cart_link['url']; ?>"><i class="bi bi-cart" aria-hidden="true"></i> Cart</a><?php
|
|
||||||
}?>
|
|
||||||
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<div class="nav-btn col col-lg-2 d-flex justify-content-end">
|
<div class="nav-btn col col-lg-2 d-flex justify-content-end">
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<a class="text-nowrap d-flex header-phone-number" href="tel:<?php echo $consumer_phone_number; ?>">
|
<a class="text-nowrap d-flex header-phone-number" href="tel:<?php echo $consumer_phone_number; ?>">
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by color-white" aria-hidden="true" style="--fa-rotate-angle: -45deg; padding-bottom: 8px;"></i> <?php echo $consumer_phone_number; ?>
|
<i class="fa-solid fa-phone-volume fa-rotate-by color-white" aria-hidden="true" style="--fa-rotate-angle: -45deg; padding-bottom: 8px;"></i> <?php echo $consumer_phone_number; ?>
|
||||||
</a>
|
</a>
|
||||||
<?php else : ?>
|
|
||||||
<a class="text-nowrap d-flex header-phone-number" href="tel:<?php echo $business_phone_number; ?>">
|
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by color-white" aria-hidden="true" style="--fa-rotate-angle: -45deg; padding-bottom: 8px;"></i> <?php echo $business_phone_number; ?>
|
|
||||||
</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-lg-1 d-flex justify-content-center">
|
<div class="col col-lg-1 d-flex justify-content-center">
|
||||||
<a class="text-decoration-none" href="/?s=" aria-label="Search pages, posts and products on this website"><i class="bi bi-search" aria-hidden="true"></i></a>
|
<a class="text-decoration-none" href="/?s=" aria-label="Search pages, posts and products on this website"><i class="bi bi-search" aria-hidden="true"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row d-md-none p-1">
|
<div class="row d-md-none p-1">
|
||||||
<div class="col d-flex justify-content-center top-bar-mobile">
|
<div class="col d-flex justify-content-center top-bar-mobile">
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<a class="text-nowrap d-flex top-bar-mobile-phone" href="tel:<?php echo $consumer_phone_number; ?>">
|
<a class="text-nowrap d-flex top-bar-mobile-phone" href="tel:<?php echo $consumer_phone_number; ?>">
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by" aria-hidden="true" style="--fa-rotate-angle: -45deg;"></i> <?php echo $consumer_phone_number; ?>
|
<i class="fa-solid fa-phone-volume fa-rotate-by" aria-hidden="true" style="--fa-rotate-angle: -45deg;"></i> <?php echo $consumer_phone_number; ?>
|
||||||
</a>
|
</a>
|
||||||
<?php else : ?>
|
|
||||||
<a class="text-nowrap d-flex top-bar-mobile-phone" href="tel:<?php echo $business_phone_number; ?>">
|
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by" aria-hidden="true" style="--fa-rotate-angle: -45deg;"></i> <?php echo $business_phone_number; ?>
|
|
||||||
</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -116,17 +72,6 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarText">
|
<div class="collapse navbar-collapse" id="navbarText">
|
||||||
<?php
|
<?php
|
||||||
if( $stylesheet === 'business-brand' ) {
|
|
||||||
wp_nav_menu(array(
|
|
||||||
'theme_location' => 'business-menu',
|
|
||||||
'container' => false,
|
|
||||||
'menu_class' => '',
|
|
||||||
'fallback_cb' => '__return_false',
|
|
||||||
'items_wrap' => '<ul id="%1$s" class="navbar-nav me-auto mb-2 mb-lg-0 nav-justified w-100 %2$s">%3$s</ul>',
|
|
||||||
'depth' => 3,
|
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
wp_nav_menu(array(
|
wp_nav_menu(array(
|
||||||
'theme_location' => 'consumer-menu',
|
'theme_location' => 'consumer-menu',
|
||||||
'container' => false,
|
'container' => false,
|
||||||
@@ -136,36 +81,7 @@
|
|||||||
'depth' => 4,
|
'depth' => 4,
|
||||||
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
'walker' => new bootstrap_5_wp_nav_menu_walker()
|
||||||
));
|
));
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<ul class="d-md-none top-nav-mobile">
|
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="text-decoration-none text-nowrap" href="/business/">Healthcare and Senior Living</a>
|
|
||||||
</li>
|
|
||||||
<?php else : ?>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="text-decoration-none text-nowrap" href="/">For Consumers</a>
|
|
||||||
</li>
|
|
||||||
<?php endif; ?>
|
|
||||||
<!-- <li class="nav-item">
|
|
||||||
<a class="text-decoration-none text-nowrap" href="#"><i class="bi bi-person-circle text-white" aria-hidden="true"></i> Login</a>
|
|
||||||
</li> -->
|
|
||||||
<!-- <li class="nav-item">
|
|
||||||
<a class="text-decoration-none text-nowrap" href="#"><i class="bi bi-cart text-white" aria-hidden="true"></i> Cart</a>
|
|
||||||
</li> -->
|
|
||||||
</ul>
|
|
||||||
<!-- <div class="nav-btn d-flex justify-content-center">
|
|
||||||
<?php if( $stylesheet == 'consumer-brand' ) : ?>
|
|
||||||
<a class="text-nowrap d-flex header-phone-number" href="tel:<?php echo $consumer_phone_number; ?>">
|
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by color-white" aria-hidden="true" style="--fa-rotate-angle: -45deg;"></i> <?php echo $consumer_phone_number; ?>
|
|
||||||
</a>
|
|
||||||
<?php else : ?>
|
|
||||||
<a class="text-nowrap d-flex header-phone-number" href="tel:<?php echo $business_phone_number; ?>">
|
|
||||||
<i class="fa-solid fa-phone-volume fa-rotate-by color-white" aria-hidden="true" style="--fa-rotate-angle: -45deg;"></i> <?php echo $business_phone_number; ?>
|
|
||||||
</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
135
wp/wp-content/themes/medicalalert/helpers/SecuredContent.php
Normal file
135
wp/wp-content/themes/medicalalert/helpers/SecuredContent.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
/** Salesforce Api Url */
|
||||||
|
define("IPER_SALESFORCE_API_URL","https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest");
|
||||||
|
|
||||||
|
/** Salesforce Brand ID */
|
||||||
|
define("IPER_SALESFORCE_BRAND","MedicalAlert");
|
||||||
|
|
||||||
|
/** Encryption key */
|
||||||
|
define("IPER_ENCRYPTION_KEY","potEgc8+5f32y+jpXSz/NqFEPuVWoT95V7aYiyRNjpQ=");
|
||||||
|
|
||||||
|
/** Signature */
|
||||||
|
define("IPER_SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAwCSPvGdoZsC1Q4btJETb9fnkM/ne
|
||||||
|
zBA4F4f0bX3JymVZ83H9F1CTykhQWjZ8WiAuPFGHNaUESGtfr0pWF113KrY5ei910WcvcBKd1w6w
|
||||||
|
JrpUdhWC5bAgoXfLoS0itbX7TvIKrvoXcHbtAPMEDyMNv/Dy/RstNTqUBzF2fLKTwTkCAwEAAQKB
|
||||||
|
gAZuct0554sLnPBOCOFePgVFaw0OVRXRiSnIeYxcry92Ja+ku3WsqHXB5pFOd5UbX1DSOHYO4vjQ
|
||||||
|
QfCqdVKXj1CGF+5snE8elE8uuN4Y7OgZ9PBdTJ/V2gevtkYQsjtjteZn3ay3Eic1ItVWSXL4NjZh
|
||||||
|
4eso3QN+yQsfUhFAOD59AkD1W58VDN8vHWymyJebIGPwKFf6bQpUCeEJVCR5gBvz0wGEQWaLoiyJ
|
||||||
|
HGSenfpDTo9eiKWvGOnlB11wLvvatqATAkDIeg5jQvj2M6aQRr1k+UETGtjz9BN5vwwpJt+qnVbR
|
||||||
|
hypoSsBtqBMxTSbWizNzMen1JaOw/Vck8Iei4FoatrsDAkAnSZp5hmweYTnKowgToOYfyHX99YPX
|
||||||
|
3RUZp02H3wmay0jM4qQG69rxwYgjFezC5ktyubK+DOE2+SzvD7boWKHdAkBup+B1LaxZyRyxGjrE
|
||||||
|
F0iyEOmbjieJ1cgSluByPjKDqMXhlxEr9c/SMLG1TlRxyyVGKSZ3NP765sEXSBq0EBSdAkCX8h79
|
||||||
|
z9mezZxyRcdod2Sk4t1hWUf0AnLhkzfAgdQoNwY692uBYXsyKXGufLNkb+RznASmn5Lr6NanIL4c
|
||||||
|
6S9P
|
||||||
|
-----END PRIVATE KEY-----");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(!class_exists("EncryptedContent")){
|
||||||
|
class EncryptedContent{
|
||||||
|
public $IV;
|
||||||
|
public $Data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!class_exists("MessageContentSigned")){
|
||||||
|
class MessageContentSigned{
|
||||||
|
public $Content;
|
||||||
|
public $Signature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists("MessageContent")){
|
||||||
|
class MessageContent{
|
||||||
|
public $Body;
|
||||||
|
public $Timestamp;
|
||||||
|
public $Uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!class_exists("SecuredContent")){
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
|
class SecuredContent {
|
||||||
|
protected $encrption_key;
|
||||||
|
protected $signature_key;
|
||||||
|
protected $cipher;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
/*$this->encrption_key = get_option("encrption_key");
|
||||||
|
$this->signature_key = get_option("signature_key");*/
|
||||||
|
$this->encrption_key = IPER_ENCRYPTION_KEY;
|
||||||
|
$this->signature_key = IPER_SIGNATURE_KEY;
|
||||||
|
$this->cipher = 'AES-256-CBC';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function encode_content($raw_content)
|
||||||
|
{
|
||||||
|
$message_content = new MessageContent();
|
||||||
|
$message_content->Body = $raw_content;
|
||||||
|
$message_content->Timestamp = date('Y-m-d H:i:s', time());
|
||||||
|
$message_content->Uid = self::guid();
|
||||||
|
|
||||||
|
// create signature & pack message
|
||||||
|
$signed_message = new MessageContentSigned();
|
||||||
|
$signed_message->Content = json_encode($message_content);
|
||||||
|
$signed_message->Signature = $this->generate_signature($signed_message->Content);
|
||||||
|
|
||||||
|
// create initialization vector & encode data
|
||||||
|
$iv_size = 16;
|
||||||
|
$iv = openssl_random_pseudo_bytes($iv_size);
|
||||||
|
$key = base64_decode($this->encrption_key);
|
||||||
|
$data = json_encode($signed_message);
|
||||||
|
$padding = 16 - (strlen($data) % 16);
|
||||||
|
$data .= str_repeat(chr($padding), $padding);
|
||||||
|
$cipher_text = openssl_encrypt($data, $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
|
// store content inside an encrypted container
|
||||||
|
$encrypted_content = new EncryptedContent();
|
||||||
|
$encrypted_content->IV = base64_encode($iv);
|
||||||
|
$encrypted_content->Data = base64_encode($cipher_text);
|
||||||
|
|
||||||
|
return $encrypted_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function decode_content($encrypted_string)
|
||||||
|
{
|
||||||
|
$encrypted_content = json_decode($encrypted_string);
|
||||||
|
|
||||||
|
// decode data
|
||||||
|
|
||||||
|
$key = base64_decode($this->encrption_key);
|
||||||
|
$iv = base64_decode($encrypted_content->IV);
|
||||||
|
$message = openssl_decrypt(base64_decode($encrypted_content->Data), $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
$message = json_decode(substr($message, 0));
|
||||||
|
$signature = $this->generate_signature($message->Content);
|
||||||
|
|
||||||
|
return json_decode($message->Content)->Body;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generate_signature($message_content)
|
||||||
|
{
|
||||||
|
$private_key = openssl_get_privatekey($this->signature_key);
|
||||||
|
|
||||||
|
openssl_sign($message_content, $signature, $this->signature_key, 'SHA256');
|
||||||
|
|
||||||
|
openssl_free_key($private_key);
|
||||||
|
|
||||||
|
return base64_encode($signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function guid()
|
||||||
|
{
|
||||||
|
if (function_exists('com_create_guid') === true)
|
||||||
|
{
|
||||||
|
return trim(com_create_guid(), '{}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,10 +51,6 @@ $AddOnsOnetime = array_filter(get_field("one_time_add_ons", "options"), function
|
|||||||
return in_array($item["product_id"], $addOn["available_for_products"]);
|
return in_array($item["product_id"], $addOn["available_for_products"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// $normalizedonetime = strtolower(preg_replace('/\s+/', '', $_SESSION["one-time"]));
|
|
||||||
// $normalizedgetaddon = strtolower(preg_replace('/\s+/', '', $_GET["add-on"]));
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($_GET["add-on"])) {
|
if (isset($_GET["add-on"])) {
|
||||||
$addon = $_GET["add-on"];
|
$addon = $_GET["add-on"];
|
||||||
if (stripos($addon, "Professional Install") !== false) {
|
if (stripos($addon, "Professional Install") !== false) {
|
||||||
@@ -62,44 +58,42 @@ if (isset($_GET["add-on"])) {
|
|||||||
unset($_SESSION["one-time"]);
|
unset($_SESSION["one-time"]);
|
||||||
} else {
|
} else {
|
||||||
foreach ($AddOnsOnetime as $ao) {
|
foreach ($AddOnsOnetime as $ao) {
|
||||||
if ($_GET["add-on"] == $ao["label"]) { // compare the $_GET param to available add ons
|
if ($_GET["add-on"] == $ao["label"]) {
|
||||||
$_SESSION["one-time"][$_GET["add-on"]] = $ao;
|
$_SESSION["one-time"][$_GET["add-on"]] = $ao;
|
||||||
//$_SESSION["one-time"][$_GET["add-on"]] = "Professional Install";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var_dump($_SESSION["one-time"]);
|
|
||||||
|
|
||||||
// next, check the $_GET params to see if we need to toggle any add ons
|
|
||||||
if (isset($_GET["add-on"])) {
|
if (isset($_GET["add-on"])) {
|
||||||
|
$add_on_modified = false;
|
||||||
|
|
||||||
if (isset($_SESSION["addOns"][$_GET["add-on"]])) {
|
if (isset($_SESSION["addOns"][$_GET["add-on"]])) {
|
||||||
unset($_SESSION["addOns"][$_GET["add-on"]]);
|
unset($_SESSION["addOns"][$_GET["add-on"]]);
|
||||||
|
$add_on_modified = true;
|
||||||
} else {
|
} else {
|
||||||
foreach ($availableAddOns as $ao) {
|
foreach ($availableAddOns as $ao) {
|
||||||
if ($_GET["add-on"] == $ao["label"]) { // compare the $_GET param to available add ons
|
if ($_GET["add-on"] == $ao["label"]) {
|
||||||
$_SESSION["addOns"][$_GET["add-on"]] = $ao;
|
$_SESSION["addOns"][$_GET["add-on"]] = $ao;
|
||||||
|
$add_on_modified = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// back button toggles weird things when we are constantly juggling the
|
if ($add_on_modified) {
|
||||||
// $_SESSION based on $_GET, so let's redirect to a clean CART url
|
$redirect_url = remove_query_arg('add-on', wc_get_cart_url());
|
||||||
header("Location: ".wc_get_cart_url());
|
wp_redirect($redirect_url);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// next, check to see if we have any add ons currently enabled
|
|
||||||
foreach ($availableAddOns as $key => $addOn) {
|
foreach ($availableAddOns as $key => $addOn) {
|
||||||
$availableAddOns[$key]["in_cart"] = isset($_SESSION["addOns"][$addOn["label"]]);
|
$availableAddOns[$key]["in_cart"] = isset($_SESSION["addOns"][$addOn["label"]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//$AddOnsOnetime["in_cart"] = isset($_SESSION["one-time"]);
|
|
||||||
foreach ($AddOnsOnetime as $mykey => $oneTime) {
|
foreach ($AddOnsOnetime as $mykey => $oneTime) {
|
||||||
$AddOnsOnetime[$mykey]["in_cart"] = isset($_SESSION["one-time"]);
|
$AddOnsOnetime[$mykey]["in_cart"] = isset($_SESSION["one-time"]);
|
||||||
}
|
}
|
||||||
@@ -124,9 +118,6 @@ foreach ($availableAddOns as &$addOn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$addOnOutput = site()->view("add_on_chooser", [
|
$addOnOutput = site()->view("add_on_chooser", [
|
||||||
"add-ons" => $availableAddOns,
|
"add-ons" => $availableAddOns,
|
||||||
"add-ons-onetime" => $AddOnsOnetime,
|
"add-ons-onetime" => $AddOnsOnetime,
|
||||||
@@ -157,7 +148,4 @@ echo site()->view("cart", [
|
|||||||
"couponSummary" => $couponSummary,
|
"couponSummary" => $couponSummary,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// take it away from here!
|
|
||||||
|
|
||||||
|
|
||||||
get_footer();
|
get_footer();
|
||||||
|
|||||||
Reference in New Issue
Block a user