Skip to content

Instantly share code, notes, and snippets.

@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Refresh the cart summary
Created October 9, 2020 11:53
Woo Discount Rules v2 - Refresh the cart summary
add_action('woocommerce_before_cart', function (){
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery( window ).load(function() {
jQuery("[name='update_cart']").removeAttr('disabled');
jQuery("[name='update_cart']").trigger("click");
});
});
</script>
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - refresh check out page
Created October 15, 2020 07:15
Woo Discount Rules v2 - refresh check out page
add_action('woocommerce_review_order_before_cart_contents', function (){
if (!WC()->cart->is_empty()){
WC()->cart->calculate_totals();
}
if ( is_checkout() ) {
?>
<script type="text/javascript">
jQuery(function($){
$(document.body).trigger("update_checkout")
});
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Remove Duplicate promotion messages
Created October 15, 2020 11:30
Woo Discount Rules v2 - Remove Duplicate promotion messages
add_action('woocommerce_before_cart', function (){
if(class_exists('\Wdr\App\Router')){
remove_action('woocommerce_before_cart', array(\Wdr\App\Router::$manage_discount, 'showAppliedRulesMessages'));
remove_action('woocommerce_before_cart', array(\Wdr\App\Router::$manage_discount, 'displayPromotionMessages'));
}
}, 11);
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Tag + Attribute Filter (and) combination
Created October 20, 2020 05:30
Woo Discount Rules v2 - Tag + Attribute Filter (and) combination
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){
//'array(419,420)' - give rule id as you needed
if(in_array($rule->getId(),array(419)) && class_exists('\Wdr\App\Helpers\Woocommerce')){
$rule_filter = $rule->getFilter();
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
$parent_product_id = \Wdr\App\Helpers\Woocommerce::getProductParentId($product_id);
$product_id = !empty($parent_product_id) ? $parent_product_id : $product_id;
if($rule_filter){
foreach($rule_filter as $filter){
$type = isset($filter->type) ? $filter->type : '';
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Get rules start date and end date
Created October 20, 2020 07:29
Woo Discount Rules v2 - Get rules start date and end date
if ( class_exists('\Wdr\App\Controllers\ManageDiscount')) {
$rules = \Wdr\App\Controllers\ManageDiscount::$available_rules;
$start_date = $end_date = array();
if(!empty($rules) && is_array($rules)){
foreach ($rules as $rule){
if($rule->rule->enabled == 1){
$rule_id = $rule->rule->id;
//get timestamp
$start_date_timestamp = $rule->rule->date_from;
$end_date_timestamp = $rule->rule->date_to;
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Taxonomies + Attribute Filter (and) combination
Created October 21, 2020 05:00
Woo Discount Rules v2 - Taxonomies + Attribute Filter (and) combination
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){
//'array(1,2,3)' - give rule id as you needed
if(in_array($rule->getId(),array(1,2)) && class_exists('\Wdr\App\Helpers\Woocommerce')){
$rule_filter = $rule->getFilter();
$has_filter_passed = array();
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
$parent_product_id = \Wdr\App\Helpers\Woocommerce::getProductParentId($product_id);
if($rule_filter){
foreach($rule_filter as $filter){
$type = isset($filter->type) ? $filter->type : '';
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Refresh checkout when change payment
Last active October 21, 2020 09:05
Woo Discount Rules v2 - Refresh checkout when change payment
add_action('woocommerce_review_order_before_payment', function(){
if (!is_cart()) {
?>
<script type="text/javascript">
(function ($) {
$('form.checkout').on('change', '.shipping_method', function () {
$('body').trigger('update_checkout');
location.reload();
});
})(jQuery);
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Bulk table override
Created October 27, 2020 04:36
Woo Discount Rules v2 - Bulk table override
<?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 - update checkout when change zip code
Last active October 27, 2020 13:26
Woo Discount Rules v2 - update checkout when change zip code
add_action('woocommerce_review_order_before_cart_contents', function (){
if ( is_checkout() ) { ?>
<script type="text/javascript">
jQuery('form.checkout').on('change', '#billing_postcode', function () {
jQuery('body').trigger('update_checkout');
});
</script>
<?php
}
});
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Subtotal condition compatible for Price Based on Country for WooCommerce by Oscar Gare
Last active October 28, 2020 14:29
Woo Discount Rules v2 - Subtotal condition compatible for Price Based on Country for WooCommerce by Oscar Gare
add_filter('advanced_woo_discount_rules_converted_currency_value', function($price) {
if(is_numeric($price) && !empty($price)) {
if(function_exists('wcpbc_the_zone')){
if(wcpbc_the_zone()){
$price = wcpbc_the_zone()->get_exchange_rate_price( $price, true, 'generic', '' );
}
}
}
return $price;
}, 10);