array(),);
$rules_option_array = get_option('xa_dp_rules', $dummy_option);
foreach ($rules_option_array as $rule_type => $rule_array) {
if (!empty($selected_type) && $rule_type != $selected_type)
continue;
$offertp = ucwords($rule_type);
$offertp = str_replace('Cat_combinational', 'Category Combinational ', $offertp);
$offertp = str_replace('Buy_get_free_rules', 'BOGO', $offertp);
$offertp = explode('_', $offertp);
$offertp = $offertp[0];
$offertp = $offertp . ' Offers';
if (empty($rule_array))
continue;
echo "
";
echo "
" . $offertp . "
";
echo ""
. "Offer Name | "
. "Buy Minimum | "
. "Buy Maximum | "
. "Offer value | "
. "Maximum Discount | "
. "Valid Till | "
. "
";
foreach ($rule_array as $ruleno => $rule) {
$fromdate = $rule['from_date'];
$todate = $rule['to_date'];
$user_role = $rule['allow_roles'];
$offer_name = $rule['offer_name'];
if ($user_role == 'all' || current_user_can($user_role)) {
} else {
continue;
}
$now = date('d-m-Y');
$return = false;
if (empty($fromdate) && empty($todate)) {
} elseif (empty($fromdate) && empty($todate) == false && (strtotime($now) <= strtotime($todate))) {
} elseif (empty($fromdate) == false && (strtotime($now) >= strtotime($fromdate)) && empty($todate)) {
} elseif ((strtotime($now) >= strtotime($fromdate)) && (strtotime($now) <= strtotime($todate))) {
} else {
continue;
}
$rule['max_discount'] = empty($rule['max_discount']) ? '-' : wc_price($rule['max_discount']);
$rule['max'] = empty($rule['max']) ? '-' : ($rule['max'] . " " . $rule['check_on']);
$rule['min'] = empty($rule['min']) ? '-' : ($rule['min'] . " " . $rule['check_on']);
$rule['value'] = empty($rule['value']) ? '-' : ($rule['value'] . "(" . $rule['discount_type'] . ")");
echo ""
. "" . $rule['offer_name'] . " | "
. "" . $rule['min'] . " | "
. "" . $rule['max'] . " | "
. "" . $rule['value'] . " | "
. "" . $rule['max_discount'] . " | "
. "" . $rule['to_date'] . " | "
. "
";
}
echo "
";
}
}
function get_product_category_by_id($category_id) {
$term = get_term_by('id', $category_id, 'product_cat', 'ARRAY_A');
return $term['name'];
}
function eh_categories_search_select2_field() {
$selected_categories = array();
if (isset($_GET['category_id'])) {
$selected_categories = array($_GET['category_id']);
}
$product_category = get_terms('product_cat', array('fields' => 'id=>name', 'hide_empty' => false, 'orderby' => 'title', 'order' => 'ASC',));
echo 'var selectbox =\''";
}
function eh_product_search_select2_field($name = 'product_id', $style = "width:100%;", $tab = 'product_rules', $multiple = true) {
if (is_wc_version_gt_eql('2.7')) {
echo '";
} else {
?>
=');
}
if (!function_exists('eha_get_wc_version')) {
function eha_get_wc_version() {
// If get_plugins() isn't available, require it
if (!function_exists('get_plugins'))
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Create the plugins folder and file variables
$plugin_folder = get_plugins('/' . 'woocommerce');
$plugin_file = 'woocommerce.php';
// If the plugin version number is set, return it
if (isset($plugin_folder[$plugin_file]['Version'])) {
return $plugin_folder[$plugin_file]['Version'];
} else {
// Otherwise return null
global $woocommerce;
return get_option('woocommerce_version', null);
}
}
}
function eha_get_products_from_category_by_ID($category_id) {
$products_IDs = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'product',
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $category_id,
'operator' => 'IN',
)
)
));
return $products_IDs->posts;
}
function xa_init_wc_functions() {
if (!function_exists('wc_get_price_including_tax')) {
function wc_get_price_including_tax($product, $args = array()) {
$args = wp_parse_args($args, array(
'qty' => '',
'price' => '',
));
$price = '' !== $args['price'] ? max(0.0, (float) $args['price']) : $product->get_price();
$qty = '' !== $args['qty'] ? max(0.0, (float) $args['qty']) : 1;
if ('' === $price) {
return '';
} elseif (empty($qty)) {
return 0.0;
}
$line_price = $price * $qty;
$return_price = $line_price;
if ($product->is_taxable()) {
if (!wc_prices_include_tax()) {
$tax_rates = WC_Tax::get_rates($product->get_tax_class());
$taxes = WC_Tax::calc_tax($line_price, $tax_rates, false);
$tax_amount = WC_Tax::get_tax_total($taxes);
$return_price = round($line_price + $tax_amount, wc_get_price_decimals());
} else {
$tax_rates = WC_Tax::get_rates($product->get_tax_class());
$base_tax_rates = WC_Tax::get_base_tax_rates($product->get_tax_class(true));
/**
* If the customer is excempt from VAT, remove the taxes here.
* Either remove the base or the user taxes depending on woocommerce_adjust_non_base_location_prices setting.
*/
if (!empty(WC()->customer) && WC()->customer->get_is_vat_exempt()) {
$remove_taxes = apply_filters('woocommerce_adjust_non_base_location_prices', true) ? WC_Tax::calc_tax($line_price, $base_tax_rates, true) : WC_Tax::calc_tax($line_price, $tax_rates, true);
$remove_tax = array_sum($remove_taxes);
$return_price = round($line_price - $remove_tax, wc_get_price_decimals());
/**
* The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations.
* e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.
* This feature is experimental @since 2.4.7 and may change in the future. Use at your risk.
*/
} elseif ($tax_rates !== $base_tax_rates && apply_filters('woocommerce_adjust_non_base_location_prices', true)) {
$base_taxes = WC_Tax::calc_tax($line_price, $base_tax_rates, true);
$modded_taxes = WC_Tax::calc_tax($line_price - array_sum($base_taxes), $tax_rates, false);
$return_price = round($line_price - array_sum($base_taxes) + array_sum($modded_taxes), wc_get_price_decimals());
}
}
}
return apply_filters('woocommerce_get_price_including_tax', $return_price, $qty, $product);
}
}
if (!function_exists('wc_get_price_excluding_tax')) {
/**
* For a given product, and optionally price/qty, work out the price with tax excluded, based on store settings.
* @since 3.0.0
* @param WC_Product $product
* @param array $args
* @return float
*/
function wc_get_price_excluding_tax($product, $args = array()) {
$args = wp_parse_args($args, array(
'qty' => '',
'price' => '',
));
$price = '' !== $args['price'] ? max(0.0, (float) $args['price']) : $product->get_price();
$qty = '' !== $args['qty'] ? max(0.0, (float) $args['qty']) : 1;
if ('' === $price) {
return '';
} elseif (empty($qty)) {
return 0.0;
}
if ($product->is_taxable() && wc_prices_include_tax()) {
$tax_rates = WC_Tax::get_base_tax_rates($product->get_tax_class(true));
$taxes = WC_Tax::calc_tax($price * $qty, $tax_rates, true);
$price = WC_Tax::round($price * $qty - array_sum($taxes));
} else {
$price = $price * $qty;
}
return apply_filters('woocommerce_get_price_excluding_tax', $price, $qty, $product);
}
}
if (!function_exists('wc_format_price_range')) {
function wc_format_price_range($from, $to) {
$price = sprintf(_x('%1$s – %2$s', 'Price range: from-to', 'woocommerce'), is_numeric($from) ? wc_price($from) : $from, is_numeric($to) ? wc_price($to) : $to);
return apply_filters('woocommerce_format_price_range', $price, $from, $to);
}
}
if (!function_exists('wc_format_sale_price')) {
function wc_format_sale_price($regular_price, $sale_price) {
$price = '' . ( is_numeric($regular_price) ? wc_price($regular_price) : $regular_price ) . ' ' . ( is_numeric($sale_price) ? wc_price($sale_price) : $sale_price ) . '';
return apply_filters('woocommerce_format_sale_price', $price, $regular_price, $sale_price);
}
}
}