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_remove_data_store_filters_while_search_products', '__return_false');
/**
* Check user has discount or not.
*/
if (class_exists('\Wdr\App\Controllers\DiscountCalculator') && !empty(\Wdr\App\Controllers\DiscountCalculator::$applied_rules)) {
// the user has discounts
} else {
// the user doesn't have any discounts
}
/**
@AnanthFlycart
AnanthFlycart / UpsellWP: Brief "Choose any" attribute variants
Last active July 15, 2024 12:23
UpsellWP: Brief "Choose any" attribute variants
add_filter('cuw_get_product_data', function ($data, $product, $args) {
if (empty($args['to_display'])) {
return $data;
}
if (!empty($data['is_variable']) && method_exists($product, 'get_available_variations')) {
$has_choose_any_variant = false;
$available_variations = $product->get_available_variations();
if (!empty($available_variations) && is_array($available_variations)) {
foreach ($available_variations as $variation_data) {
if (!empty($variation_data['attributes'])) {
@AnanthFlycart
AnanthFlycart / UpsellWP Side Cart: Show slider after product adding to cart (not through AJAX)
Created July 12, 2024 09:23
UpsellWP Side Cart: Show slider after product adding to cart (not through AJAX)
add_action('wp_footer', function () {
if (did_action('woocommerce_add_to_cart') >= 1) { ?>
<script>
jQuery(document).ready(function () {
jQuery('.uwpmc-widget-container').trigger('click');
});
</script>
<?php
}
}, 100);
@AnanthFlycart
AnanthFlycart / UpsellWP: Show fixed discount price without trimming zeros
Created July 3, 2024 06:04
UpsellWP: Show fixed discount price without trimming zeros
add_filter('cuw_discount_text', function ($text, $product, $discount, $display_in) {
if (!empty($discount['type']) && $discount['type'] == 'fixed_price' && is_numeric($discount['value'])) {
if (method_exists('\CUW\App\Helpers\WC', 'getPriceToDisplay') && method_exists('\CUW\App\Helpers\WC', 'formatPriceRaw')) {
$price = apply_filters('cuw_convert_price', $discount['value'], 'fixed_price');
$price = \CUW\App\Helpers\WC::getPriceToDisplay($product, $price, 1, $display_in);
$text = html_entity_decode(\CUW\App\Helpers\WC::formatPriceRaw($price));
}
}
return $text;
}, 100, 4);
@AnanthFlycart
AnanthFlycart / UpsellWP: Add Custom conditions
Created June 20, 2024 12:01
UpsellWP: Custom conditions
/**
* Register custom condition.
*/
add_filter('cuw_conditions', function ($conditions) {
if (empty($conditions['custom']) && class_exists('CUWCustomCondition')) {
$conditions['custom'] = [
'name' => __("Custom Conditions", 'checkout-upsell-woocommerce'),
'group' => __("Custom", 'checkout-upsell-woocommerce'),
'handler' => new CUWCustomCondition(),
'campaigns' => [
@AnanthFlycart
AnanthFlycart / UpsellWP: Load upsell popup dynamically on product page
Created June 10, 2024 11:09
UpsellWP: Load upsell popup dynamically on product page
add_filter('cuw_load_upsell_popup_dynamically_in_product_page', '__return_true');
@AnanthFlycart
AnanthFlycart / UpsellWP: Add Custom offer template
Created May 2, 2024 06:38
UpsellWP: Add Custom offer template
add_filter('cuw_templates', function ($templates) {
$templates['offer/custom-template-1'] = [
'title' => '{discount} offer',
'description' => 'Hey there, you can get this offer by just clicking the checkbox below to add this offer to your order, you will never get such a discount on any other place on this site.',
'cta_text' => 'Get this exclusive offer now !',
'image_id' => 0,
'styles' => [
'template' => ['border-width' => 'medium', 'border-style' => 'dashed', 'border-color' => '#c3c4c7', 'background-color' => '#fbfbfb'],
'title' => ['font-size' => '', 'color' => '#ffffff', 'background-color' => '#32cd32'],
'description' => ['font-size' => '', 'color' => '#525f7a', 'background-color' => '#d1ecf1'],
@AnanthFlycart
AnanthFlycart / UpsellWP - Apply discount via get_price filter event
Created March 14, 2024 13:18
UpsellWP - Apply discount via get_price filter event
add_action('woocommerce_before_calculate_totals', function ($cart) {
if (!method_exists('\CUW\App\Helpers\Discount', 'getPrice')) {
return;
}
foreach ($cart->get_cart() as $cart_item) {
if (isset($cart_item['cuw_offer']) && isset($cart_item['data']) && $offer = $cart_item['cuw_offer']) {
if (!empty($offer['discount']) && isset($offer['discount']['type']) && $offer['discount']['type'] != 'no_discount') {
$offer_price = \CUW\App\Helpers\Discount::getPrice($cart_item['data'], $offer['discount']);
if (is_object($cart_item['data'])) {
$cart_item['data']->cuw_price = $offer_price;
@AnanthFlycart
AnanthFlycart / UpsellWP - Redirect to product page when click add to cart button in upsell popup
Created March 13, 2024 12:08
UpsellWP - Redirect to product page when click add to cart button in upsell popup
add_action('wp_footer', function () { ?>
<script>
jQuery(document.body).on('click', ".cuw-modal .cuw-popup-products .cuw-product .cuw-add-product-to-cart", function () {
let product_id = jQuery(this).closest('.cuw-product').data('id');
jQuery(this).closest('.cuw-product').data('id', 0);
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'cuw_get_permalink',