Skip to content

Instantly share code, notes, and snippets.

View AnanthFlycart's full-sized avatar

Anantharaj B AnanthFlycart

View GitHub Profile
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Increase campaign offers max limit
Last active March 8, 2024 11:07
CUW: Increase campaign offers max limit
add_filter('cuw_offers_per_campaign', function ($limit, $campaign_type) {
if (in_array($campaign_type, ['checkout_upsells', 'cart_upsells'])) {
$limit = 10;
}
return $limit;
}, 100, 2);
add_filter('cuw_coupon_base_url', function($url) {
$url = 'https://www.example.com'; // here you can change your own url here
return $url;
});
add_filter('cuw_show_upsell_item_text', '__return_false');
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Hide FBT template checkboxes
Last active December 26, 2023 05:04
CUW: Hide FBT template checkboxes
add_action('wp_footer', function() { ?>
<style>
.cuw-fbt-products .cuw-product .cuw-product-checkbox {
display: none;
}
</style>
<script type="text/javascript">
jQuery(".cuw-fbt-products .cuw-product-wrapper .cuw-product-image").on('click', function() {
return false;
});
add_action('wp_footer', function() { ?>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery(".cuw-fbt-products .cuw-product .cuw-product-checkbox").prop('checked', false);
jQuery(".cuw-fbt-products .is_main .cuw-product-checkbox").prop('checked', true);
jQuery(".cuw-fbt-products .cuw-buy-section .cuw-product:first .cuw-product-checkbox").prop('checked', true);
});
</script>
<?php
});
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Show Added to Cart Popup when Redirect to the cart page option is enabled
Created December 21, 2023 05:54
CUW: Show Added to Cart Popup when Redirect to the cart page option is enabled
add_filter('woocommerce_add_to_cart_redirect', function ($url) {
if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {
$url = add_query_arg(['cuw_show_popup' => '1'], empty($url) ? wc_get_cart_url() : $url);
}
return $url;
}, 100, 2);
add_action('wp_footer', function () {
if (isset($_GET['cuw_show_popup'])
&& method_exists('\CUW\App\Pro\Modules\Campaigns\UpsellPopups', 'getCampaignToDisplay')
global $cuw_offer_max_quantity;
$cuw_offer_max_quantity = 4; // here you can change maximum upsell offer quantity to choose
add_filter('cuw_offer_processed_data', function ($offer) use ($cuw_offer_max_quantity) {
$offer['product']['max_qty'] = empty($offer['product']['max_qty']) || $offer['product']['max_qty'] > $cuw_offer_max_quantity ? $cuw_offer_max_quantity : $offer['product']['max_qty'];
if (!empty($offer['product']['variants'])) {
foreach ($offer['product']['variants'] as $key => $variant) {
if (empty($variant['max_qty']) || $variant['max_qty'] > $cuw_offer_max_quantity) {
$offer['product']['variants'][$key]['max_qty'] = $cuw_offer_max_quantity;
}
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Improve FBT template mobile view
Last active December 19, 2023 07:33
CUW: FBT mobile grid 2x2 view
@media only screen and (max-width: 480px) {
.cuw-fbt-products.cuw-mobile-responsive .cuw-gird {
gap: 24px !important;
justify-content: left !important;}
.cuw-fbt-products.cuw-mobile-responsive .cuw-product {
width: 120px !important; }
.cuw-fbt-products.cuw-mobile-responsive .cuw-product-card {
width: 120px !important; }
.cuw-fbt-products.cuw-mobile-responsive .cuw-product-image {
height: 120px !important;
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Show upsell product even it is already in cart
Last active December 15, 2023 11:44
CUW: Show upsell product even it is already in cart
add_filter('cuw_upsell_popup_skip_product_is_already_in_cart', '__return_false');
add_action('plugins_loaded', function () {
if (function_exists('is_ajax') && is_ajax() && method_exists('CUW\App\Pro\Modules\Campaigns\ProductAddons', 'addProductsToCart')) {
add_action('woocommerce_add_to_cart', ['\CUW\App\Pro\Modules\Campaigns\ProductAddons', 'addProductsToCart'], 15);
}
});