Skip to content

Instantly share code, notes, and snippets.

View AnanthFlycart's full-sized avatar

Anantharaj B AnanthFlycart

View GitHub Profile
add_filter('woocommerce_cart_item_quantity', function ($product_quantity, $cart_item_key, $cart_item) {
if (isset($cart_item['cuw_offer'])) {
return '<input type="hidden" class="qty" name="cart[' . esc_attr($cart_item_key) . '][qty]" value="' . esc_attr($cart_item['quantity']) . '">';
}
return $product_quantity;
}, 100000, 3);
add_filter('cuw_cart_item_offer_text', function ($text, $cart_item) {
if (method_exists('\CUW\App\Helpers\Offer', 'getText')) {
$text = \CUW\App\Helpers\Offer::getText($cart_item['data'], $cart_item['cuw_offer']['discount'], 'cart');
$text = '<span class="cuw-offer-text">' . __("Save", 'checkout-upsell-woocommerce') . ' ' . $text . '</span>';
}
return $text;
}, 100, 2);
// NOTE: This snippets works in Checkout Upsell plugin version 1.4.1 and above
add_action('woocommerce_mini_cart_contents', function () {
if (defined('CUW_VERSION') && version_compare(CUW_VERSION, '1.4.1', '>=')) {
if (method_exists('\CUW\App\Modules\Campaigns\CartUpsells', 'getOffersHtml')) {
echo \CUW\App\Modules\Campaigns\CartUpsells::getOffersHtml('shortcode', true, false);
}
}
}, 20);
add_filter('cuw_fbt_products_display_locations', function ($locations) {
$locations['woocommerce_after_add_to_cart_form'] = esc_html__("After add to cart button", 'checkout-upsell-woocommerce');
return $locations;
});
add_action('wp_loaded', function() {
if (class_exists('CUW\App\Modules\Conditions\Base')) {
class CUWAdvancedProducts extends \CUW\App\Modules\Conditions\Base
{
// to check condition
public function check($condition, $data) {
$product_ids = [];
foreach ($data['products'] as $product) {
$product_ids[] = $product['id'];
if ($product['variation_id']) {
// add stripe_cc payment method
add_filter('cuw_post_purchase_before_payment_supported_payment_gateways', function ($methods) {
$methods['stripe_cc'] = __('Credit Cards (Stripe) by Payment Plugins', 'woo-stripe-payment');
return $methods;
}, 100);
// handle request after payment succeed
add_filter('cuw_payment_successful_result', function ($result, $order) {
if ($order->get_payment_method() == 'stripe_cc') {
if (substr($result['redirect'], 0, 1) == '#' && function_exists('wc_get_checkout_url')) {
add_filter('cuw_fbt_product_ids_to_display', function ($ids, $product) {
rsort($ids);
return $ids;
}, 100, 2);
add_filter('cuw_post_purchase_supported_payment_gateways', function($payment_methods) {
return array_merge([
'woo-mercado-pago-basic' => __('Mercado Pago - Checkout Pro', 'woocommerce-mercadopago'),
'woo-mercado-pago-credits' => __('Mercado Pago - Installments without card', 'woocommerce-mercadopago'),
'woo-mercado-pago-custom' => __('Mercado pago - Customized Checkout', 'woocommerce-mercadopago') . ' (' . __('Debit and Credit', 'woocommerce-mercadopago') . ')',
'woo-mercado-pago-pix' => __('Mercado pago - Customized Checkout', 'woocommerce-mercadopago') . ' (' . __('Pix', 'woocommerce-mercadopago') . ')',
'woo-mercado-pago-ticket' => __('Mercado pago - Customized Checkout', 'woocommerce-mercadopago') . ' (' . __('Invoice', 'woocommerce-mercadopago') . ')',
], $payment_methods);
});
@AnanthFlycart
AnanthFlycart / Checkout Upsell: Exclude upsell offers from the coupon discounts
Created September 8, 2023 04:35
CUW: Exclude upsell offers from the coupon discounts
add_filter('woocommerce_coupon_get_items_to_validate', function ($items) {
foreach ($items as $key => $item) {
if (isset($item->object['cuw_offer'])) {
unset($items[$key]);
}
}
return $items;
}, 100);
add_filter('cuw_offer_template_product_quantity', function ($html, $offer) {
if (!empty($offer['id']) && !empty($offer['product']['id']) && function_exists('wc_get_product')) {
$product = wc_get_product($offer['product']['id']);
if (!empty($product) && ($product->is_virtual() || $product->is_downloadable())) {
$html = '<input type="hidden" name="quantity" value="1"/>';
}
}
return $html;
}, 100, 2);