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: Refresh page after offer added to cart
Last active March 26, 2024 12:49
CUW: Refresh page after offer added to cart
add_action('wp_footer', function () { ?>
<script>
jQuery(document.body).on('cuw_offer_added_to_cart', function() {
location.reload();
});
</script>
<?php
}, 100000);
// Note: You might need to choose "Use a shortcode [cuw_fbt]" as a display location in FBT campaign
add_filter('cuw_fbt_products_display_locations', function($locations) {
$locations['cuw_fbt_shortcode'] = esc_html__("Use a shortcode [cuw_fbt]", 'checkout-upsell-woocommerce');
return $locations;
});
add_shortcode('cuw_fbt', function() {
ob_start();
do_action('cuw_fbt_shortcode');
return ob_get_clean();
});
// Checkout Upsell: Compatibility script for FOX - Currency Switcher (formerly WOOCS)
if (!function_exists('get_woocs_convertion_rate') && !function_exists('cuw_get_converted_price')) {
function get_woocs_convertion_rate() {
global $WOOCS;
if (is_object($WOOCS) && method_exists($WOOCS, 'get_currencies')) {
$currencies = $WOOCS->get_currencies();
$convert_to_current_currency = false;
if (isset($WOOCS->is_geoip_manipulation) && $WOOCS->is_geoip_manipulation) {
$convert_to_current_currency = true;
}
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Refresh page after coupon added or removed
Created August 23, 2023 11:08
CUW: Refresh page after coupon added / removed
add_action('wp_footer', function() { ?>
<script>
jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () {
location.reload();
});
</script>
<?php
});
add_action('cuw_after_init', function() {
if (class_exists('CUW\App\Modules\Conditions\Base')) {
class CUWLanguages extends \CUW\App\Modules\Conditions\Base
{
// to check condition
public function check($condition, $data) {
return isset($condition['value']) && $condition['value'] == cuw_get_current_language();
}
// to load condition template
add_action('wp_footer', function() {
?>
<script type="text/javascript">
jQuery('.cuw-offer .cuw-product-image img:nth-child(2)').remove();
</script>
<?php
});
add_action('admin_enqueue_scripts', function() {
if (isset($_GET['page']) && $_GET['page'] == 'checkout-upsell-woocommerce') {
if (function_exists('wp_scripts') && isset(wp_scripts()->registered)) {
foreach (array_keys(wp_scripts()->registered) as $script) {
if (strpos($script, 'cuw_') === false && strpos($script, 'bootstrap') !== false) {
wp_deregister_script($script);
}
}
}
}
add_filter('advanced_woo_discount_rules_disable_strikeout_for_product_types', function ($product_types) {
$product_types[] = 'yith_bundle';
return $product_types;
}, 10);
add_filter('cuw_cart_item_offer_label', function ($label) {
$label = esc_html__("Add On", 'checkout-upsell-woocommerce'); // here you can change the text
return $label;
});
add_filter('option_cuw_offers_add_limit', function($value) {
$value = 10; // here you can set the maximum number of offers a customer can pick at a time
return $value;
});