Skip to content

Instantly share code, notes, and snippets.

@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Compatible with WooCommerce Product Add-Ons Ultimate by Plugin Republic
Created August 20, 2021 12:21
Woo Discount Rules v2 - Compatible with WooCommerce Product Add-Ons Ultimate by Plugin Republic
add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function($price, $cart_item, $cart_object, $calculated_cart_item_discount){
$add_on_price = 0;
if(isset($cart_item) && isset($cart_item['product_extras']) && !empty($cart_item['product_extras'])){
$price_with_extras = isset($cart_item['product_extras']['price_with_extras']) ? $cart_item['product_extras']['price_with_extras'] : 0;
$original_price = isset($cart_item['product_extras']['original_price']) ? $cart_item['product_extras']['original_price'] : 0;
$add_on_price = $price_with_extras - $original_price;
$price = $price + $add_on_price;
}
return $price;
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Bulk table Range customization Example
Last active August 11, 2021 12:25
Woo Discount Rules v2 - Bulk table Range customization Example
<?php
// override path: your theme/advanced_woo_discount_rules/discount_table.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;
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Check Rule is enabled or not
Last active August 10, 2021 05:55
Woo Discount Rules v2 - Check Rule is enabled or not
if ( class_exists('\Wdr\App\Controllers\ManageDiscount')) {
$manage_discount = new \Wdr\App\Controllers\ManageDiscount();
$rules = $manage_discount->getDiscountRules();
foreach ($rules as $rule){
//loop
//$rule->getRuleDiscountType() ->it will return discount type
//array(1,2) -> change your rule id instead of 1,2
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Bulk table override
Last active August 9, 2021 06:44
Woo Discount Rules v2 - Bulk table override
<?php
//Over ride path: Past this code in your theme path-> Yourtheme/advanced_woo_discount_rules/discount_table.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;
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Remove out of stock item and disabled variants in change variants
Created August 3, 2021 07:29
Woo Discount Rules v2 - Remove out of stock item and disabled variants in change variants
<?php
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
//override path: yourtheme/woo-discount-rules-pro/buy-x-get-y-select-auto-add-variant.php
?>
<div class="awdr-select-free-variant-product-toggle"><?php _e('Change Variant', 'woo-discount-rules-pro') ?></div>
<div class="awdr-select-variant-product">
<?php
foreach ($available_products as $available_product) { //parent_id
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Check WDR Free shipping is enabled
Created August 2, 2021 07:51
Woo Discount Rules v2 - Check WDR Free shipping is enabled
if ( class_exists('\WDRPro\App\Rules\FreeShipping')) {
// below method return true when wdr free shipping enabled
$wdr_free_shiiping = \WDRPro\App\Rules\FreeShipping::cartHasFreeShipping();
}
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options (Product page strike out)
Created July 30, 2021 13:50
Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options (Product page strike out)
add_action( 'wp_footer', function () {
$currency_code = '$';
if(function_exists('get_woocommerce_currency_symbol')){
$currency_code = html_entity_decode(get_woocommerce_currency_symbol());
}
?>
<script type="application/javascript">
function compatiblePriceStrikeOut() {
var $form = jQuery('form.cart').first();
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options
Last active July 29, 2021 05:59
Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
if($calculate_discount_from == "regular_price"){
$product_price = get_post_meta( $product_id, '_regular_price', true);
}else{
$product_price = get_post_meta( $product_id, '_price', true);
}
}
return $product_price;
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Disable coupon discount rules will work (Translation conflict resolve)
Created July 28, 2021 09:40
Woo Discount Rules v2 - Disable coupon discount rules will work (Translation conflict resolve)
add_filter('advanced_woo_discount_rules_notice_on_remove_coupon_while_having_a_discount', function( $msg, $coupon_code){
return sprintf(__('Sorry, it is not possible to apply coupon "%s" as you already have a discount applied in cart.', 'woo-discount-rules'), $coupon_code);
},10, 2);
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Exclude discount for add on price compatible for Woocommerce Custom Product Addons By Acowebs
Last active July 21, 2021 12:42
Woo Discount Rules v2 - Exclude discount for add on price compatible for Woocommerce Custom Product Addons By Acowebs
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
if($calculate_discount_from == "regular_price"){
$product_price = get_post_meta( $product_id, '_regular_price', true);
}else{
$product_price = get_post_meta( $product_id, '_price', true);
}
}
return $product_price;