Skip to content

Instantly share code, notes, and snippets.

View AnanthFlycart's full-sized avatar

Anantharaj B AnanthFlycart

View GitHub Profile
// Fix - Rule Discount Type selection issue from ARForms plugin
add_action('admin_enqueue_scripts', function() {
if (isset($_GET['page']) && $_GET['page'] == 'woo_discount_rules') {
wp_deregister_script('bootstrap-datepicker');
}
}, 100);
// Fix - Dynamic Strikeout not Update during Add to Cart (Ajax) in Product page
add_action('wp_footer', function () {
if (function_exists('is_product') && is_product()) {
?>
<script>
jQuery(function($) {
$(document.body).on('added_to_cart removed_from_cart wc_fragments_refreshed', function() {
$('[name="quantity"]').trigger('change');
});
});
// Fix - Strikeout price issue
add_filter('woocommerce_get_price_html', function ($price_html, $product){
global $post;
$woo_uom_output = get_post_meta($post->ID, '_woo_uom_input', true);
if ($woo_uom_output) {
$content = '<span class="uom">' . esc_attr($woo_uom_output, 'woocommerce-uom') . '</span>';
$price_html = str_replace($content, '', $price_html);
$price_html .= $content;
}
return $price_html;
// Change - load assets priority (increase to higher)
add_action('advanced_woo_discount_rules_after_initialize', function() {
if (class_exists('\Wdr\App\Router') && (!is_admin() || wp_doing_ajax())) {
remove_action('wp_enqueue_scripts', array(\Wdr\App\Router::$manage_discount, 'loadAssets'));
add_action('wp_enqueue_scripts', array(\Wdr\App\Router::$manage_discount, 'loadAssets'), 100000);
}
});
// Fix - BXGY Free Cart item quantity data getting (from JavaScript) issue
add_action('woocommerce_cart_item_quantity', function($product_quantity, $cart_item_key, $cart_item) {
if (is_numeric($product_quantity)) {
$product_quantity = $product_quantity . ' ' . sprintf('<input type="hidden" name="cart[%s][qty]" value="%s" />', $cart_item_key, $product_quantity);
}
return $product_quantity;
}, 1000, 3);
// Use discount rule discount instead of YITH bundle discount
add_filter('yith_wcpb_bundled_item_calculated_discount', function($price, $yith_discount, $regular_price, $product_id) {
if (function_exists('wc_get_product') && $product = wc_get_product($product_id)) {
$discount = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, 1, 0, 'discounted_price', true, true);
if ($discount !== false) {
$price = $regular_price - $discount;
}
}
return $price;
}, 100, 4);
if (class_exists('\Wdr\App\Router')) {
$applied_rule_ids = [];
$manage_discount = \Wdr\App\Router::$manage_discount;
$applied_rules = $manage_discount::$calculator::$applied_rules;
if (!empty($applied_rules)) {
foreach ($applied_rules as $rule) {
$applied_rule_ids[] = (int) $rule->rule->id;
}
}
// Show discount bar in shop/category/loop page before add to cart button
add_action('woocommerce_after_shop_loop_item', function() {
global $product;
do_action('advanced_woo_discount_rules_load_discount_bar', $product);
}, 1);
// Fix - Strikeout not shown correctly, same strikeout issues, etc. (may third party plugin prices not shown correctly)
add_action('wp_loaded', function() {
if(class_exists('\Wdr\App\Router')) {
remove_all_filters('woocommerce_get_price_html');
remove_all_filters('woocommerce_variable_price_html');
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtml'), 100, 2);
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtmlSalePriceAdjustment'), 9, 2);
add_filter('woocommerce_variable_price_html', array(\Wdr\App\Router::$manage_discount, 'getVariablePriceHtml'), 100, 2);
}
}, 100);
// Stop modify price html for guest role
add_filter('advanced_woo_discount_rules_modify_price_html', function($modify, $price_html, $product, $quantity) {
if (!is_user_logged_in()) {
$modify = false;
}
return $modify;
}, 100, 4);