get_phone update
This commit is contained in:
@@ -161,102 +161,24 @@ function wpdocs_excerpt_more( $more ) {
|
||||
}
|
||||
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );
|
||||
|
||||
function update_individual_fields_11($entry, $form)
|
||||
{
|
||||
echo '</br>';
|
||||
echo '</br>';
|
||||
|
||||
$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 .= '
|
||||
<div class="container">
|
||||
<h3> Membership Verified</h3>
|
||||
<p>Thank you for providing your Member ID, your discount code will be applied to the your product selection.</p>
|
||||
<p>Your discount code is:</p>
|
||||
<p><b>E6Y8</b></p>
|
||||
|
||||
</div>
|
||||
';
|
||||
|
||||
return $aarp_member;
|
||||
global $aarp_member;
|
||||
}
|
||||
|
||||
function aarp_form_notfound()
|
||||
{
|
||||
$aarp_member_notfound .= '
|
||||
<div class="container">
|
||||
<h3> Membership record could not be found.</h3>
|
||||
<p>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</p>
|
||||
<p><a class="member-button text-nowrap button--primary products-list-link" href="/aarp-member-benefit">Try Again</a></p>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $aarp_member_notfound;
|
||||
global $aarp_member_notfound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function get_phone
|
||||
* Get phone number from database, campaigns and google forwarding numbers
|
||||
* Function: get_phone
|
||||
* Retrieves and formats a phone number from either session or database.
|
||||
*
|
||||
* @return string Formatted phone number (e.g., 123-456-7890) or an error message if invalid.
|
||||
*/
|
||||
function get_phone()
|
||||
{
|
||||
function get_phone() {
|
||||
// Local helper function as an anonymous function
|
||||
$format_phone = function ($num) {
|
||||
$num = preg_replace("/[^0-9]/", "", $num);
|
||||
if (strlen($num) < 10) {
|
||||
return "Invalid Number";
|
||||
}
|
||||
return substr($num, 0, 3) . "-" . substr($num, 3, 3) . "-" . substr($num, 6);
|
||||
};
|
||||
|
||||
if (isset($_SESSION['SESScampaignphone'])) {
|
||||
$num = $_SESSION["SESScampaignphone"];
|
||||
|
||||
$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;
|
||||
}
|
||||
$num = $_SESSION['SESScampaignphone'] ?? get_option('cta_tel', true);
|
||||
return $format_phone($num);
|
||||
}
|
||||
|
||||
add_shortcode('op', 'get_phone');
|
||||
@@ -377,4 +299,3 @@ function gtm_datalayer_init() {?>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user