" . __('Include additional conditions (if necessary)', 'woo-discount-rules') . "
" . __('Popular conditions:', 'woo-discount-rules') . "
";
}
/**
* bogoToolTipDescriptionForIndividualProduct
* @return mixed
*/
public static function bogoToolTipDescriptionForIndividualProduct()
{
return $content = __("Individual Product :
This counts the total quantity of each product / line item separately.
Example:
If a customer wanted to buy 2 quantities of Product A, 3 quantities of Product B, then count will be maintained at the product level.
2 - count of Product A
3 - Count of Product B
In case of variable products, the count will be based on each variant because WooCommerce considers a variant as a product itself.", 'woo-discount-rules');
}
/**
* bogoToolTipDescriptionForFilterTogether
* @return mixed
*/
public static function bogoToolTipDescriptionForFilterTogether()
{
return $content = __("Filter set above :
This will count the quantities of products set in the 'Filter' section.
Example: If you selected a few categories there, it will count the quantities of products in those categories added in cart. If you selected a few products in the filters section, then it will count the quantities together.
Example: Let’s say, you wanted to offer a Bulk Quantity discount for Category A and chosen Category A in the filters. So when a customer adds 1 quantity each of X, Y and Z from Category A, then the count here is 3.", 'woo-discount-rules');
}
/**
* bogoToolTipDescriptionForvariants
* @return mixed
*/
public static function bogoToolTipDescriptionForvariants()
{
return $content = __('All variants in each product together :
Useful when applying discounts based on variable products and you want the quantity to be counted based on the parent product.
Example:
Say, you have Product A - Small, Medium, Large.
If a customer buys 2 of Product A - Small, 4 of Product A - Medium, 6 of Product A - Large, then the count will be: 6+4+2 = 12
', 'woo-discount-rules');
}
/**
* Get available coupon names
* */
public static function getAvailableCouponNameFromRules(){
if(self::$available_coupon_names === null){
$available_rules = ManageDiscount::$available_rules;
$coupon_names = array();
if(!empty($available_rules)){
foreach ($available_rules as $available_rule){
$discount_type = $available_rule->getRuleDiscountType();
if($discount_type == 'wdr_bulk_discount'){
$adjustment = $available_rule->getBulkAdjustments();
if(isset($adjustment->apply_as_cart_rule) && $adjustment->apply_as_cart_rule == 1){
if(!empty($adjustment->cart_label)){
$coupon_names[] = $adjustment->cart_label;
} else {
$coupon_names[] = $available_rule->getTitle();
}
}
} else if($discount_type == 'wdr_simple_discount'){
$adjustment = $available_rule->getProductAdjustments();
if(isset($adjustment->apply_as_cart_rule) && $adjustment->apply_as_cart_rule == 1){
if(!empty($adjustment->cart_label)){
$coupon_names[] = $adjustment->cart_label;
} else {
$coupon_names[] = $available_rule->getTitle();
}
}
} else if($discount_type == 'wdr_cart_discount'){
$adjustment = $available_rule->getCartAdjustments();
if(!empty($adjustment->label)){
$coupon_names[] = $adjustment->label;
} else {
$coupon_names[] = $available_rule->getTitle();
}
} else if($discount_type == 'wdr_set_discount'){
$adjustment = json_decode($available_rule->rule->set_adjustments);
if(isset($adjustment->apply_as_cart_rule) && $adjustment->apply_as_cart_rule == 1){
if(!empty($adjustment->cart_label)){
$coupon_names[] = $adjustment->cart_label;
} else {
$coupon_names[] = $available_rule->getTitle();
}
}
}
}
}
$coupon_name_from_config = Configuration::getInstance()->getConfig('discount_label_for_combined_discounts', __('Cart discount', 'woo-discount-rules'));
$coupon_names[] = (empty($coupon_name_from_config))? __('Cart discount', 'woo-discount-rules'): $coupon_name_from_config;
foreach ($coupon_names as $key => $coupon_name){
$coupon_names[$key] = apply_filters('woocommerce_coupon_code', $coupon_name);
}
self::$available_coupon_names = $coupon_names;
}
return self::$available_coupon_names;
}
/**
* Remove error message for our coupons as sometime the coupon doesn't validate because of event calls before calculate totals
* */
public static function removeErrorMessageForOurCoupons($err, $err_code, $coupon){
if($err_code == 101){
if(!empty($coupon)){
$coupon_code = Woocommerce::getCouponCode($coupon);
if(in_array($coupon_code, self::getAvailableCouponNameFromRules())){
$err = '';
}
}
}
return $err;
}
public static function create_nonce($action = -1)
{
return wp_create_nonce($action);
}
protected static function verify_nonce($nonce, $action = -1)
{
if (wp_verify_nonce($nonce, $action)) {
return true;
} else {
return false;
}
}
public static function validateRequest($method, $awdr_nonce = null)
{
if ($awdr_nonce === null) {
if (isset($_REQUEST['awdr_nonce']) && !empty($_REQUEST['awdr_nonce'])) {
if (self::verify_nonce(wp_unslash($_REQUEST['awdr_nonce']), $method)) {
return true;
}
}
} else {
if (self::verify_nonce(wp_unslash($awdr_nonce), $method)) {
return true;
}
}
die(__('Invalid token', 'woo-discount-rules'));
}
public static function filterSelect2SearchQuery($query)
{
return esc_sql(stripslashes($query));
}
public static function displayCompatibleCheckMessages()
{
if (version_compare(WDR_VERSION, '2.6.1', '>=')) {
if (defined('WDR_PRO_VERSION')) {
if (version_compare(WDR_PRO_VERSION, '2.6.1', '<')) {
$url = esc_url(admin_url() . "plugins.php");
$plugin_page = '' . __('Update now', 'woo-discount-rules') . '';
?>
Woo Discount Rules PRO 2.0 plugin. Please update the plugin to latest version to run smoothly. %s', 'woo-discount-rules'), $plugin_page); ?>
]*>).*?(<\/\2>)/is', "$1$3", $html);
$allowed_html = array(
'br' => array(),
'strong' => array(),
'span' => array('class' => array(), 'style' => array()),
'div' => array('class' => array(), 'style' => array()),
'p' => array('class' => array(), 'style' => array()),
);
// Since v2.5.5
$allowed_html = apply_filters( 'advanced_woo_discount_rules_allowed_html_elements_and_attributes', $allowed_html);
return wp_kses($html, $allowed_html);
} catch (\Exception $e) {
return '';
}
}
/**
* check the given content is json or not
* @param $string
* @return bool
*/
static function isJson($string)
{
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
/**
* sanitize the json data
* @param $data
* @return bool|false|mixed|string
*/
static function sanitizeJson($data)
{
$arr = array();
if (is_array($data)) {
$arr = $data;
} elseif (is_object($data)) {
$encoded = wp_json_encode($data);
$arr = json_decode($encoded, true);
} elseif (self::isJson($data)) {
$arr = json_decode($data, true);
}
$result = array();
if (is_array($arr) && !empty($arr)) {
foreach ($arr as $key => $value) {
if (is_array($value) || is_object($value)) {
$value = self::sanitizeJson($value);
$result[sanitize_key($key)] = $value;
} else {
if (is_string($value)) {
$value = sanitize_text_field($value);
} elseif (is_int($value)) {
$value = intval($value);
} elseif (is_float($value)) {
$value = floatval($value);
} else {
$value = sanitize_text_field($value);
}
$result[sanitize_key($key)] = $value;
}
}
}
return $result;
}
}