Skip to content

Instantly share code, notes, and snippets.

View AnanthFlycart's full-sized avatar

Anantharaj B AnanthFlycart

View GitHub Profile
@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',
@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_upsell_popup_triggers', function($triggers) {
$triggers['place_order'] = [
'title' => __('Click "Place order" button', 'checkout-upsell-woocommerce'),
'description' => __('Shows when the "Place order" button is clicked.', 'checkout-upsell-woocommerce')
. '<br><span class="text-dark">' . __('NOTE: This trigger does not work on the WooCommerce Checkout block.', 'checkout-upsell-woocommerce') . '</span>',
'target' => '#place_order',
'event' => 'click',
'pages' => ['checkout'],
'dynamic_content' => false,
'continue_text' => __("Place order", 'checkout-upsell-woocommerce'),
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')