Skip to content

Instantly share code, notes, and snippets.

View AnanthFlycart's full-sized avatar

Anantharaj B AnanthFlycart

View GitHub Profile
add_filter('advanced_woo_discount_rules_calculate_discount_for_cart_item', function ($calculate_discount, $cart_item){
if(!empty($cart_item['is_deposit'])){
$calculate_discount = false;
}
return $calculate_discount;
}, 100, 2);
add_filter('advanced_woo_discount_rules_process_cart_item_for_cheapest_rule', function($calculate_discount, $cart_item){
if(!empty($cart_item['is_deposit'])){
$calculate_discount = false;
}
add_action('wp_loaded', function() {
if (class_exists('\Wdr\App\Router')) {
remove_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtml'), 100);
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtml'), 9, 2);
remove_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtmlSalePriceAdjustment'), 9);
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtmlSalePriceAdjustment'), 8, 2);
}
});
add_action('cuw_fbt_products_added_to_cart', function () {
if (function_exists('wp_redirect') && function_exists('wc_get_cart_url')) {
wp_redirect(wc_get_cart_url());
exit;
}
});
/**
* @param int|float $value Fixed discount price (in base curreny)
* @param string $type Discount type.
*/
add_filter('advanced_woo_discount_rules_converted_currency_value', function($value, $type) {
// here you can update price ($value) based on the current currency
return $value;
}, 100, 2);
add_filter('woocommerce_available_variation', function($data, $variable_product, $variation) {
if (isset($data['display_price'])) {
$discount_details = apply_filters('advanced_woo_discount_rules_get_product_discount_details', false, $variation);
if ($discount_details !== false) {
$data['display_price'] = $discount_details['discounted_price_based_on_tax_settings'];
}
}
return $data;
}, 100, 3);
add_filter('woocommerce_get_price_html', function ($price_html) {
if (class_exists('\Wdr\App\Router') && method_exists(\Wdr\App\Router::$manage_discount, 'removeDuplicateStrikeoutPrice')) {
return \Wdr\App\Router::$manage_discount->removeDuplicateStrikeoutPrice($price_html);
}
return $price_html;
}, 1000);
add_filter('woocommerce_order_item_get_formatted_meta_data', function($meta_data, $item) {
if (did_action('woocommerce_email_header')) {
if (did_action('woocommerce_email_header') != did_action('woocommerce_email_footer')) {
foreach ($meta_data as $key => $data) {
if (isset($data->key) && in_array($data->key, ['cuw_offer_text', 'cuw_discount_text'])) {
unset($meta_data[$key]);
}
}
}
}
// Round discount to 1 decimal by using woocommerce round discount function and it may be round half down (1.5 into 1)
add_filter('advanced_woo_discount_rules_discount_prices_of_product', function ($discount_prices, $product, $quantity, $cart_item){
if (function_exists('wc_round_discount') && function_exists('wc_get_price_decimals')) {
$precision = 1;
if(isset($discount_prices['discounted_price'])){
$discount_prices['discounted_price'] = wc_round_discount($discount_prices['discounted_price'], $precision);
}
if(isset($discount_prices['discounted_price_with_tax'])){
$discount_prices['discounted_price_with_tax'] = wc_round_discount($discount_prices['discounted_price_with_tax'], $precision);
}
add_filter('cuw_remove_applied_offers_when_cart_contains_no_other_products', '__return_false');
add_action('cuw_offer_added_to_cart', function($key, $data) {
if (function_exists('WC') && isset(WC()->cart) && method_exists(WC()->cart, 'get_cart_contents')) {
foreach (WC()->cart->get_cart_contents() as $cart_item_key => $cart_item) {
if ($cart_item_key != $key && method_exists(WC()->cart, 'remove_cart_item')) {
WC()->cart->remove_cart_item($cart_item_key);
}
}
}
}, 10, 2);
add_action('wp_loaded', function() {
remove_all_filters('woocommerce_sale_flash');
add_filter('woocommerce_sale_flash', function($html, $post, $product) {
if (function_exists('wolmart_wc_get_loop_prop') && function_exists('wolmart_get_option')) {
$html = '';
$show_labels = wolmart_wc_get_loop_prop( 'show_labels', array( 'hot', 'stock', 'sale', 'new' ) );
if ( is_array( $show_labels ) && count( $show_labels ) ) {
// Featured label
if ( $product->is_featured() && in_array( 'hot', $show_labels ) ) {
$html .= '<label class="product-label label-featured">' . esc_html__( 'Hot', 'wolmart' ) . '</label>';