Skip to content

Instantly share code, notes, and snippets.

@Balakrishnan-flycart
Balakrishnan-flycart / Remove Free (hidden)product Dynamically for cart rule
Created December 23, 2019 06:09
Remove free hidden product dynamically if not match cart rule condition
add_action('woocommerce_before_cart', function(){
if(class_exists('FlycartWooDiscountRulesCartRules')){
if(empty(FlycartWooDiscountRulesCartRules::$applied_coupon)){
if(!empty(WC()->cart)){
$cart_items = WC()->cart->get_cart();
foreach ($cart_items as $key => $cart_item){
$not_visible = false;
$product = $cart_item['data'];
if(method_exists($product, 'is_visible')){
if(!$product->is_visible()){
@Balakrishnan-flycart
Balakrishnan-flycart / woo_discount_rules_exclude_product_from_discount.php
Created December 24, 2019 13:15
woo discount rules exclude product from discount in specific category using priority id
add_filter('woo_discount_rules_exclude_product_from_discount', function($return, $product, $id, $rule, $cart_item){
$priority_id = array(3); //Enter the priority id for which you need discount. i,e: array(1,2,3)
$category_id = array(22); //Enter the category id for which you need discount. i,e: array(1,2,3)
if(in_array($id,$priority_id)){
if (method_exists($product, 'get_category_ids')) {
if ($product->is_type('variation')) {
if (method_exists($product, 'get_parent_id')) {
$parent_id = $product->get_parent_id();
if(!empty($parent_id)){
$product = wc_get_product($parent_id);
@Balakrishnan-flycart
Balakrishnan-flycart / discount-table.php
Created January 7, 2020 08:06
Offer table horizontal view
<?php
/**
* List matched Rules in Table format
*
* This template can be overridden by copying it to yourtheme/plugin-folder-name/discount-table.php
*/
if (!defined('ABSPATH')) exit; // Exit if accessed directly
if (!isset($table_data) || empty($table_data)) return false;
$base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : array());
$show_discount_table_header = isset($base_config['show_discount_table_header']) ? $base_config['show_discount_table_header'] : 'show';
@Balakrishnan-flycart
Balakrishnan-flycart / cart_style.css
Created January 8, 2020 07:51
Woo discount rules: Strike through disappear in cart page
del .cont__price{
text-decoration:line-through;
}
@Balakrishnan-flycart
Balakrishnan-flycart / woo_discount_rules_before_apply_discount.php
Last active January 9, 2020 11:41
WooCommerce Gravity Forms Conflict
if(!function_exists('woo_discount_rules_before_apply_discount_method')){
function woo_discount_rules_before_apply_discount_method($amount, $product, $cart_item){
if(isset($cart_item['_gform_total']) && !empty($cart_item['_gform_total'])){
$addon_price = (int)$cart_item['_gform_total'];
$amount = isset($amount) && !empty($amount) ? (int)$amount : 0;
$total_amount = $amount+$addon_price;
return $total_amount;
}
return $amount;
}
@Balakrishnan-flycart
Balakrishnan-flycart / Discount rules v2: Subscription compatible - Apply discount only for subscription price (excluding sign up fee)
Last active May 26, 2020 10:45
Discount rules v2: Subscription compatible - Apply discount only for subscription price (excluding sign up fee)
if(!function_exists('calculateProductPriceForWooDiscountRules')){
function calculateProductPriceForWooDiscountRules($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ($calculate_discount_from == 'regular_price') {
if (method_exists($product, 'get_regular_price')) {
$product_price = $product->get_regular_price();
}
} else {
if (method_exists($product, 'get_sale_price')) {
$product_price = $product->get_sale_price();
}
@Balakrishnan-flycart
Balakrishnan-flycart / Discount rules v2: Subscription compatible - Remove subscription price discount for Recurring totals(excluding sign up fee)
Created May 26, 2020 12:31
Discount rules v2: Subscription compatible - Remove subscription price discount for Recurring totals(excluding sign up fee)
add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function ($price, $cart_item, $cart_object, $calculated_cart_item_discount){
if ( !empty( $cart_object->recurring_cart_key ) ) {
$product = isset($cart_item['data']) ? $cart_item['data'] : array();
if(!empty($product)){
if (method_exists($product, 'get_sale_price')) {
$price = $product->get_sale_price();
}
if(empty($price)){
if (method_exists($product, 'get_regular_price')) {
$price = $product->get_regular_price();
@Balakrishnan-flycart
Balakrishnan-flycart / Discount rules v2: Woocommerce Deposits compatible - Remove subtotal 0
Last active June 15, 2020 07:07
Discount rules v2: Woocommerce Deposits compatible - Remove subtotal 0
add_filter('advanced_woo_discount_rules_run_discount_rules', function($run_rule, $cart){
return false;
}, 10, 2);
add_action( 'woocommerce_cart_loaded_from_session', function($cart){
if ( sizeof( $cart->cart_contents ) > 0 ) {
foreach ( $cart->cart_contents as $cart_item_key => $cart_item ) {
$cart_key = isset($cart_item['key'])? $cart_item['key'] : '';
$cart_item_data = isset($cart_item['data'])? $cart_item['data'] : '';
@Balakrishnan-flycart
Balakrishnan-flycart / Discount Rules V2: Sale badge compatible with sober theme
Last active July 7, 2020 07:48
Discount Rules V2: Sale badge compatible with sober theme
if (!function_exists('woo_discount_rules_sober_product_ribbons')) {
function woo_discount_rules_sober_product_ribbons($output, $product){
if(empty($output['onsale'])){
if ( $product->is_on_sale() ) {
$output['onsale'] = '<span class="onsale ribbon">Special Sale</span>';
}
} else {
$product_id = $product->get_id();
if(class_exists('\Wdr\App\Controllers\ManageDiscount')){
$isProductOnSale = Wdr\App\Controllers\ManageDiscount::isProductOnSale($product_id);
@Balakrishnan-flycart
Balakrishnan-flycart / Discount Rules v2: Display only max price in product page strikeout for variable products
Created July 15, 2020 12:14
Discount Rules v2: Display only max price in product page strikeout for variable products
add_filter('advanced_woo_discount_rules_format_sale_price_range', function($html, $min_price, $max_price){
$html = wc_price($max_price);
return $html;
}, 10, 3);