/** * Checks to see if a Coupon Code was supplied, and if so; what does it provide? * * @package optimizeMember\PayPal * @since 1.5 * * @param array $attr An array of Pro Form Attributes. * @param str $coupon_code Optional. A possible Coupon Code supplied by the Customer. * @param str $return Optional. Return type. One of `response|attr`. Defaults to `attr`. * @param array $process Optional. An array of additional processing routines to run here. * One or more of these values: `affiliates-1px-response|affiliates-silent-post|notifications`. * @return array|str Original array, with prices and description modified when/if a Coupon Code is accepted. * Or, if ``$return === "response"``, return a string response, indicating status. * * @todo See if it's possible to simplify this routine. * @todo Add support for tracking Coupon Code usage. * @todo Add support for a fixed number of uses. */ public static function paypal_apply_coupon($attr = FALSE, $coupon_code = FALSE, $return = FALSE, $process = FALSE) { if (($coupon_code = trim(strtolower($coupon_code))) || ($coupon_code = trim(strtolower($attr["coupon"])))) { if ($attr["accept_coupons"] && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_coupon_codes"]) { $cs = c_ws_plugin__optimizemember_utils_cur::symbol($attr["cc"]); $tx = c_ws_plugin__optimizemember_pro_paypal_utilities::paypal_tax_may_apply() ? _x(" + tax", "s2member-front", "s2member") : ""; $ps = _x("%", "s2member-front percentage-symbol", "s2member"); /**/ if (strlen($affiliate_suffix_chars = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_affiliate_coupon_code_suffix_chars"])) { if (preg_match("/^(.+?)" . preg_quote($affiliate_suffix_chars, "/") . "([0-9]+)\$/i", $coupon_code, $m)) { ($full_coupon_code = $m[0]) . ($coupon_code = $m[1]) . ($affiliate_id = $m[2]); } } unset($affiliate_suffix_chars, $m); /**/ foreach (c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_coupon_codes"])) as $_line) { if (($_line = trim($_line, " \r\n\t\v|")) && is_array($_coupon = preg_split("/\\|/", $_line))) { $coupon["code"] = !empty($_coupon[0]) ? trim(strtolower($_coupon[0])) : ""; /**/ $coupon["percentage"] = !empty($_coupon[1]) && preg_match("/%/", $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon["flat-rate"] = !empty($_coupon[1]) && !preg_match("/%/", $_coupon[1]) ? (double) $_coupon[1] : 0; /**/ $coupon["expired"] = !empty($_coupon[2]) && strtotime($_coupon[2]) < time() ? $_coupon[2] : false; /**/ $coupon["directive"] = !empty($_coupon[3]) && ($_coupon[3] = strtolower($_coupon[3])) ? preg_replace("/_/", "-", $_coupon[3]) : "all"; $coupon["directive"] = preg_match("/^(ta-only|ra-only|all)\$/", $coupon["directive"]) ? $coupon["directive"] : "all"; /**/ $coupon["singulars"] = !empty($_coupon[4]) && ($_coupon[4] = strtolower($_coupon[4])) && $_coupon[4] !== "all" ? $_coupon[4] : "all"; $coupon["singulars"] = $coupon["singulars"] !== "all" ? preg_split("/[\r\n\t\\s;,]+/", trim(preg_replace("/[^0-9,]/", "", $coupon["singulars"]), ",")) : array("all"); /**/ unset($_line, $_coupon); /**/ if ($coupon_code === $coupon["code"] && !$coupon["expired"]) { if ($coupon["singulars"] === array("all") || in_array($attr["singular"], $coupon["singulars"])) { $coupon_accepted = true; /**/ if ($coupon["flat-rate"]) { if (($coupon["directive"] === "ra-only" || $coupon["directive"] === "all") && $attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . $ra . $tx); } else { if ($coupon["directive"] === "ta-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "all" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { if ($coupon["directive"] === "all" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $ta = number_format($attr["ta"] - $coupon["flat-rate"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $ra = number_format($attr["ra"] - $coupon["flat-rate"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), $cs . number_format($coupon["flat-rate"], 2, ".", ""), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is not applicable.</div>', "s2member-front", "s2member"); } } } } } } } else { if ($coupon["percentage"]) { if (($coupon["directive"] === "ra-only" || $coupon["directive"] === "all") && $attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . $ra . $tx); } else { if ($coupon["directive"] === "ta-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"], 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "all" && $attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s, then %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr["tp"] . " " . $attr["tt"]) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"])); } else { if ($coupon["directive"] === "ra-only" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"], 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { if ($coupon["directive"] === "all" && !$attr["tp"] && !$attr["sp"]) { $coupon_applies = true; /**/ $p = $attr["ta"] / 100 * $coupon["percentage"]; $ta = number_format($attr["ta"] - $p, 2, ".", ""); $ta = $ta >= 0.0 ? $ta : "0.00"; /**/ $p = $attr["ra"] / 100 * $coupon["percentage"]; $ra = number_format($attr["ra"] - $p, 2, ".", ""); $ra = $ra >= 0.01 ? $ra : "0.01"; /**/ $desc = sprintf(_x("COUPON %s off. ( Now: %s )", "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>', "s2member-front", "s2member"), number_format($coupon["percentage"], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr["rp"] . " " . $attr["rt"], $attr["rr"]) . $tx); } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is not applicable.</div>', "s2member-front", "s2member"); } } } } } } } else { /* Else there was no discount applied at all. */ $response = sprintf(_x('<div>Coupon: <strong>%s0.00 off</strong>.</div>', "s2member-front", "s2member"), $cs); } } } else { /* Otherwise, we need a response that indicates not applicable for this purchase. */ $response = _x('<div>Sorry, your Coupon cannot be applied to this particular purchase.</div>', "s2member-front", "s2member"); } } else { if ($coupon_code === $coupon["code"] && $coupon["expired"]) { $response = sprintf(_x('<div>Sorry, your Coupon <strong>expired</strong>: <em>%s</em>.</div>', "s2member-front", "s2member"), $coupon["expired"]); } } } } /**/ if (isset($coupon_applies, $desc) && $coupon_applies) { /* translators: `%1$s` is new price/description, after coupon applied. `%2$s` is original description. */ $attr["desc"] = sprintf(_x('%1$s ~ ORIGINALLY: %2$s', "s2member-front", "s2member"), $desc, $attr["desc"]); } /**/ $attr["ta"] = isset($coupon_applies, $ta) && $coupon_applies ? $ta : $attr["ta"]; $attr["ra"] = isset($coupon_applies, $ra) && $coupon_applies ? $ra : $attr["ra"]; /**/ if (is_array($process) && (in_array("affiliates-silent-post", $process) || in_array("affiliates-1px-response", $process))) { if (isset($coupon_applies) && $coupon_applies && !empty($affiliate_id)) { if (empty($_COOKIE["idev"])) { if ($_urls = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["pro_affiliate_coupon_code_tracking_urls"]) { /**/ foreach (preg_split("/[\r\n\t]+/", $_urls) as $_url) { /**/ if ($_url = preg_replace("/%%full_coupon_code%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($full_coupon_code)), $_url)) { if ($_url = preg_replace("/%%coupon_code%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($coupon_code)), $_url)) { if ($_url = preg_replace("/%%affiliate_id%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($affiliate_id)), $_url)) { if ($_url = preg_replace("/%%user_ip%%/i", c_ws_plugin__optimizemember_utils_strings::esc_ds(urlencode($_SERVER["REMOTE_ADDR"])), $_url)) { if ($_url = trim(preg_replace("/%%(.+?)%%/i", "", $_url))) { /**/ if (!($_r = 0) && ($_url = preg_replace("/^silent-php\\|/i", "", $_url, 1, $_r)) && $_r && in_array("affiliates-silent-post", $process)) { c_ws_plugin__optimizemember_utils_urls::remote($_url, false, array("blocking" => false)); } else { if (!($_r = 0) && ($_url = preg_replace("/^img-1px\\|/i", "", $_url, 1, $_r)) && $_r && in_array("affiliates-1px-response", $process)) { if (!empty($response) && $return === "response") { $response .= "\n" . '<img src="' . esc_attr($_url) . '" style="width:0; height:0; border:0;" alt="" />'; } } } } } } } } } } } } } unset($_urls, $_url, $_r); /**/ if (empty($response)) { /* Is ``$response`` NOT set by now? If it's not, we need a default ``$response``. */ $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', "s2member-front", "s2member"); } } else { /* Otherwise, we need a default response to display. */ $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', "s2member-front", "s2member"); } } /**/ return $return === "response" ? $response : $attr; }
/** * Checks to see if a Coupon Code was supplied, and if so; what does it provide? * * @package optimizeMember\Stripe * @since 140617 * * @param array $attr An array of Pro Form Attributes. * @param string $coupon_code Optional. A possible Coupon Code supplied by the Customer. * @param string $return Optional. Return type. One of `response|attr`. Defaults to `attr`. * @param array $process Optional. An array of additional processing routines to run here. * One or more of these values: `affiliates-1px-response|affiliates-silent-post|notifications`. * * @return array|string Original array, with prices and description modified when/if a Coupon Code is accepted. * Or, if ``$return === 'response'``, return a string response, indicating status. */ public static function apply_coupon($attr = array(), $coupon_code = '', $return = '', $process = array()) { if (($coupon_code = trim(strtolower($coupon_code))) || ($coupon_code = trim(strtolower($attr['coupon'])))) { if ($attr['accept_coupons'] && $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_coupon_codes']) { $cs = c_ws_plugin__optimizemember_utils_cur::symbol($attr['cc']); $tx = c_ws_plugin__optimizemember_pro_stripe_utilities::tax_may_apply() ? _x(' + tax', 's2member-front', 's2member') : ''; $ps = _x('%', 'optimizemember-front percentage-symbol', 's2member'); $full_coupon_code = ''; // Initialize. if (strlen($affiliate_suffix_chars = $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_affiliate_coupon_code_suffix_chars'])) { if (preg_match('/^(.+?)' . preg_quote($affiliate_suffix_chars, '/') . '([0-9]+)$/i', $coupon_code, $m)) { ($full_coupon_code = $m[0]) . ($coupon_code = $m[1]) . ($affiliate_id = $m[2]); } } unset($affiliate_suffix_chars, $m); // Just a little housekeeping here. foreach (c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split('/[' . "\r\n\t" . ']+/', $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_coupon_codes'])) as $_line) { if (($_line = trim($_line, ' ' . "\r\n\t\v" . '|')) && is_array($_coupon = preg_split('/\\|/', $_line))) { $coupon['code'] = !empty($_coupon[0]) ? trim(strtolower($_coupon[0])) : ''; $coupon['percentage'] = !empty($_coupon[1]) && preg_match('/%/', $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon['flat-rate'] = !empty($_coupon[1]) && !preg_match('/%/', $_coupon[1]) ? (double) $_coupon[1] : 0; $coupon['expired'] = !empty($_coupon[2]) && strtotime($_coupon[2]) < time() ? $_coupon[2] : FALSE; $coupon['directive'] = !empty($_coupon[3]) && ($_coupon[3] = strtolower($_coupon[3])) ? preg_replace('/_/', '-', $_coupon[3]) : 'all'; $coupon['directive'] = preg_match('/^(ta-only|ra-only|all)$/', $coupon['directive']) ? $coupon['directive'] : 'all'; $coupon['singulars'] = !empty($_coupon[4]) && ($_coupon[4] = strtolower($_coupon[4])) && $_coupon[4] !== 'all' ? $_coupon[4] : 'all'; $coupon['singulars'] = $coupon['singulars'] !== 'all' ? preg_split('/[' . "\r\n\t" . '\\s;,]+/', trim(preg_replace('/[^0-9,]/', '', $coupon['singulars']), ',')) : array('all'); unset($_line, $_coupon); // Just a little housekeeping here. Unset these temporary variables. if ($coupon_code === $coupon['code'] && !$coupon['expired']) { if ($coupon['singulars'] === array('all') || in_array($attr['singular'], $coupon['singulars'])) { $coupon_accepted = TRUE; // Yes, this Coupon Code has been accepted. if ($coupon['flat-rate']) { if (($coupon['directive'] === 'ra-only' || $coupon['directive'] === 'all') && $attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . $ra . $tx); } else { if ($coupon['directive'] === 'ta-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'all' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { if ($coupon['directive'] === 'all' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $ta = number_format($attr['ta'] - $coupon['flat-rate'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $ra = number_format($attr['ra'] - $coupon['flat-rate'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), $cs . number_format($coupon['flat-rate'], 2, '.', ''), $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is not applicable.</div>', 's2member-front', 's2member'); } } } } } } } else { if ($coupon['percentage']) { if (($coupon['directive'] === 'ra-only' || $coupon['directive'] === 'all') && $attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . $ra . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . $ra . $tx); } else { if ($coupon['directive'] === 'ta-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'], 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'all' && $attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s, then %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s, then %s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ta, $attr['tp'] . ' ' . $attr['tt']) . $tx, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr'])); } else { if ($coupon['directive'] === 'ra-only' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'], 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { if ($coupon['directive'] === 'all' && !$attr['tp'] && !$attr['sp']) { $coupon_applies = TRUE; // Applying. $p = $attr['ta'] / 100 * $coupon['percentage']; $ta = number_format($attr['ta'] - $p, 2, '.', ''); $ta = $ta >= 0.5 ? $ta : '0.00'; $p = $attr['ra'] / 100 * $coupon['percentage']; $ra = number_format($attr['ra'] - $p, 2, '.', ''); $ra = $ra >= 0.5 ? $ra : '0.00'; $desc = sprintf(_x('COUPON %s off. (Now: %s)', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); $response = sprintf(_x('<div>Coupon: <strong>%s off</strong>. (Now: <strong>%s</strong>)</div>', 's2member-front', 's2member'), number_format($coupon['percentage'], 0) . $ps, $cs . c_ws_plugin__optimizemember_utils_time::amount_period_term($ra, $attr['rp'] . ' ' . $attr['rt'], $attr['rr']) . $tx); } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is not applicable.</div>', 's2member-front', 's2member'); } } } } } } } else { // Else there was no discount applied at all. $response = sprintf(_x('<div>Coupon: <strong>%s0.00 off</strong>.</div>', 's2member-front', 's2member'), $cs); } } } else { // Otherwise, we need a response that indicates not applicable for this purchase. $response = _x('<div>Sorry, your Coupon cannot be applied to this particular purchase.</div>', 's2member-front', 's2member'); } } else { if ($coupon_code === $coupon['code'] && $coupon['expired']) { $response = sprintf(_x('<div>Sorry, your Coupon <strong>expired</strong>: <em>%s</em>.</div>', 's2member-front', 's2member'), $coupon['expired']); } } } } if (isset($coupon_applies, $full_coupon_code, $desc) && $coupon_applies) { // translators: `%1$s` is new price/description, after coupon applied. `%2$s` is original description. $attr['desc'] = sprintf(_x('%1$s %2$s ~ ORIGINALLY: %3$s', 's2member-front', 's2member'), strtoupper($full_coupon_code), $desc, $attr['desc']); } $attr['ta'] = isset($coupon_applies, $ta) && $coupon_applies ? $ta : $attr['ta']; // Do we have a new Trial Amount? $attr['ra'] = isset($coupon_applies, $ra) && $coupon_applies ? $ra : $attr['ra']; // A new Regular Amount? if (is_array($process) && (in_array('affiliates-silent-post', $process) || in_array('affiliates-1px-response', $process))) { if (isset($coupon_applies) && $coupon_applies && !empty($affiliate_id)) { if (empty($_COOKIE['idev'])) { if ($_urls = $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_affiliate_coupon_code_tracking_urls']) { foreach (preg_split('/[' . "\r\n\t" . ']+/', $_urls) as $_url) { if ($_url = preg_replace('/%%full_coupon_code%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($full_coupon_code)), $_url)) { if ($_url = preg_replace('/%%coupon_code%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($coupon_code)), $_url)) { if ($_url = preg_replace('/%%(?:coupon_affiliate_id|affiliate_id)%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($affiliate_id)), $_url)) { if ($_url = preg_replace('/%%user_ip%%/i', c_ws_plugin__optimizemember_utils_strings::esc_refs(urlencode($_SERVER['REMOTE_ADDR'])), $_url)) { if ($_url = trim(preg_replace('/%%(.+?)%%/i', '', $_url))) { if (!($_r = 0) && ($_url = preg_replace('/^silent-php\\|/i', '', $_url, 1, $_r)) && $_r && in_array('affiliates-silent-post', $process)) { c_ws_plugin__optimizemember_utils_urls::remote($_url, FALSE, array('blocking' => FALSE)); } else { if (!($_r = 0) && ($_url = preg_replace('/^img-1px\\|/i', '', $_url, 1, $_r)) && $_r && in_array('affiliates-1px-response', $process)) { if (!empty($response) && $return === 'response') { $response .= '\\n' . '<img src="' . esc_attr($_url) . '" style="width:0; height:0; border:0;" alt="" />'; } } } } } } } } } } } } } unset($_urls, $_url, $_r); // Just a little housekeeping here. Unset these variables. if (empty($response)) { // Is ``$response`` NOT set by now? If it's not, we need a default ``$response``. $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', 's2member-front', 's2member'); } } else { // Otherwise, we need a default response to display. $response = _x('<div>Sorry, your Coupon is N/A, invalid or expired.</div>', 's2member-front', 's2member'); } } $attr['_coupon_applies'] = isset($coupon_applies) && $coupon_applies ? '1' : '0'; $attr['_coupon_code'] = isset($coupon_applies) && $coupon_applies ? $coupon_code : ''; $attr['_full_coupon_code'] = isset($coupon_applies) && $coupon_applies && !empty($full_coupon_code) ? $full_coupon_code : (isset($coupon_applies) && $coupon_applies ? $coupon_code : ''); $attr['_coupon_affiliate_id'] = isset($coupon_applies) && $coupon_applies && !empty($affiliate_id) && empty($_COOKIE['idev']) ? $affiliate_id : ''; return $return === 'response' ? !empty($response) ? (string) $response : '' : $attr; }
/** * Converts Currency Codes to Currency Symbols ( deprecated ). * * @package optimizeMember\Utilities * @since 1.5 * * @param str $currency Expects a 3 character Currency Code. * @return str A Currency Symbol. Defaults to the `$` sign. * * @deprecated Starting with v110531, please use: * ``c_ws_plugin__optimizemember_utils_cur::symbol()`` */ public static function currency_symbol($currency = FALSE) { return c_ws_plugin__optimizemember_utils_cur::symbol($currency); }