Skip to content

Instantly share code, notes, and snippets.

@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Recalculate total
Created November 3, 2020 08:15
Woo Discount Rules v2 - Recalculate total
add_filter('advanced_woo_discount_rules_do_recalculate_total', '__return_false');
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - subtotal based discount(from filter)
Last active June 9, 2021 13:35
Woo Discount Rules v2 - Subtotal based discount (from filter)
add_filter('advanced_woo_discount_rules_line_item_subtotal', function($line_subtotal, $cart_item, $tax_display_type){
if(class_exists('Wdr\App\Controllers\Configuration')){
$product = isset($cart_item['data']) ? $cart_item['data'] : '';
$config = new Wdr\App\Controllers\Configuration();
if(!empty($product)){
$calculate_discount_from = $config->getConfig('calculate_discount_from', 'sale_price');
if($calculate_discount_from == 'sale_price'){
$price = $product->get_sale_price();
if(empty($price)){
$price = $product->get_price();
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Remove coupon when cart is empty
Created November 5, 2020 11:03
Woo Discount Rules v2 - Remove coupon when cart is empty
add_action( 'woocommerce_cart_is_empty', function(){
if(class_exists('\Wdr\App\Helpers\Woocommerce')){
$cart_items = \Wdr\App\Helpers\Woocommerce::getCart();
if(empty($cart_items)){
if (method_exists(WC()->cart, 'get_coupons')) {
$get_coupons = WC()->cart->get_coupons();
if(!empty($get_coupons)){
foreach ( $get_coupons as $code => $coupon ){
if (method_exists(WC()->cart, 'remove_coupon')) {
WC()->cart->remove_coupon( $code );
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Bulk table override for kul-gave
Created November 6, 2020 04:57
Woo Discount Rules v2 - Bulk table override for kul-gave
<?php
if (!defined('ABSPATH')) exit; // Exit if accessed directly
if (!empty($ranges) && !empty($woocommerce)) {
if ($ranges['layout']['type'] == 'advanced') {
$i=0;
$existing_rule_id = 0;
$tag_opened = false;
foreach ($ranges as $key => $badge_settings){
if($key !== 'layout'){
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Remove Apply Tax In Fee function
Created November 10, 2020 13:21
Woo Discount Rules v2 - Remove Apply Tax In Fee function
add_action('plugins_loaded', function (){
if(class_exists('\Wdr\App\Router')){
remove_filter('advanced_woo_discount_rules_additional_fee_amount', array(\Wdr\App\Router::$manage_discount, 'applyTaxInFee'));
}
});
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Check user based conditions for bxgy discount bar
Last active November 11, 2020 14:01
Woo Discount Rules v2 - Check user based conditions for bxgy discount bar
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){
if(is_object($rule)){
$rule_type = $rule->getRuleDiscountType();
$conditions = $rule->getConditions();
$filter_passed_user_logged_in = $user_logged_in_passed = $filter_passed_user_role = $filter_passed_user_list = $user_role_passed = $user_list_passed = $has_other_conditions = false;
$condition_relationship = $rule->getRelationship('condition', 'and');
if(!empty($conditions) && $filter_passed && $rule_type == 'wdr_buy_x_get_y_discount'){
foreach($conditions as $condition){
$cart = array();
$options = isset($condition->options) ? $condition->options : array();
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Remove invalid coupon error message
Last active November 12, 2020 11:55
Woo Discount Rules v2 - Remove invalid coupon error message
add_filter( 'woocommerce_coupon_error', function($err, $err_code, $coupon){
if(is_object($coupon) && method_exists($coupon, 'get_code')){
if( in_array($coupon->get_code(), array('black friday', 'cyber monday'))){
$err = '';
}
}
return $err;
}, 30, 3 );
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - category A + category B Filter Combination
Created November 17, 2020 11:13
Woo Discount Rules v2 - category A + category B Filter Combination
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){
//'array(1,2)' - give rule id as you needed
if(in_array($rule->getId(),array(1,2)) && class_exists('\Wdr\App\Helpers\Woocommerce')){
$rule_filter = $rule->getFilter();
$categories = \Wdr\App\Helpers\Woocommerce::getProductCategories($product);
$first_category_id = array();
$second_category_id = array();
if($rule_filter){
foreach($rule_filter as $filter){
$type = isset($filter->type) ? $filter->type : '';
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Fix bulk table not triggered while change variant
Created November 24, 2020 12:01
Woo Discount Rules v2 - Fix bulk table not triggered while change variant
add_action( 'wp_footer', function(){?>
<script type="text/javascript">
(function ($) {
$(document).ready(function ($) {
function awdr_load_variation_table_customized(variation_id){
setTimeout(function(){
if(variation_id != '' && variation_id != '0'){
var data = {
action: 'wdr_ajax',
method: 'get_variable_product_bulk_table',
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Show you saved message with high priority
Created November 24, 2020 14:06
Woo Discount Rules v2 - Show you saved message with high priority
add_action('plugins_loaded', function (){
if(class_exists('\Wdr\App\Router')){
remove_action('woocommerce_cart_totals_order_total_html', array(\Wdr\App\Router::$manage_discount, 'getCartTotalPriceHtml'));
add_action('woocommerce_cart_totals_order_total_html', array(\Wdr\App\Router::$manage_discount, 'getCartTotalPriceHtml'), 9999, 1);
}
}, 11);