• Resolved mahadavid

    (@mahadavid)


    Thanks for the excellent plugin! Just installed it and already sold $450 in gift cards.

    The problem is, that when someone went to redeem their $100 gift certificate towards their $109 balance, it would not let them place the order, possibly because the $9 balance was below the $50 minimum. Not sure what else it could be.

    Any thoughts?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author pimwick

    (@pimwick)

    Requiring an order minimum amount isn’t part of the stock WooCommerce system. The Gift Card plugin does work with the Order Minimum/Maximum Amount for WooCommerce plugin by Algoritmika Ltd.

    Are you using a different plugin for the minimum order requirement?

    Thread Starter mahadavid

    (@mahadavid)

    Ah, yes, there’s a “booster” plugin that set a minimum. they have something for “Yith Gift Cards” but not for pw.

    <?php
    /**
    * Booster for WooCommerce – Module – Order Minimum Amount
    *
    * @version 5.1.0
    * @since 2.5.7
    * @author Pluggabl LLC.
    * @todo order max amount
    */

    if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly

    if ( ! class_exists( ‘WCJ_Order_Min_Amount’ ) ) :

    class WCJ_Order_Min_Amount extends WCJ_Module {

    private $yith_gift_card_discount = 0;

    /**
    * Constructor.
    *
    * @version 2.8.0
    * @since 2.5.7
    */
    function __construct() {

    $this->id = ‘order_min_amount’;
    $this->short_desc = __( ‘Order Minimum Amount’, ‘woocommerce-jetpack’ );
    $this->desc = __( ‘Minimum order amount (optionally by user role).’, ‘woocommerce-jetpack’ );
    $this->link_slug = ‘woocommerce-order-minimum-amount’;
    parent::__construct();

    if ( $this->is_enabled() ) {
    add_action( ‘init’, array( $this, ‘add_order_minimum_amount_hooks’ ) );
    }
    }

    /**
    * add_order_minimum_amount_hooks.
    *
    * @version 4.9.0
    * @since 2.5.3
    * @todo (maybe) template_redirect instead of wp
    */
    function add_order_minimum_amount_hooks() {
    $is_order_minimum_amount_enabled = false;
    if ( get_option( ‘wcj_order_minimum_amount’, 0 ) > 0 ) {
    $is_order_minimum_amount_enabled = true;
    } else {
    foreach ( wcj_get_user_roles() as $role_key => $role_data ) {
    if ( get_option( ‘wcj_order_minimum_amount_by_user_role_’ . $role_key, 0 ) > 0 ) {
    $is_order_minimum_amount_enabled = true;
    break;
    }
    }
    }
    if ( $is_order_minimum_amount_enabled ) {
    add_action( ‘woocommerce_checkout_process’, array( $this, ‘order_minimum_amount’ ) );
    add_action( ‘woocommerce_before_cart’, array( $this, ‘order_minimum_amount’ ) );
    if ( ‘yes’ === get_option( ‘wcj_order_minimum_amount_stop_from_seeing_checkout’, ‘no’ ) ) {
    add_action( ‘wp’, array( $this, ‘stop_from_seeing_checkout’ ), 100 );
    }
    }
    add_action( ‘yith_ywgc_apply_gift_card_discount_after_cart_total’, array( $this, ‘get_yith_gift_cards_discount’ ), 10, 2 );
    }

    /**
    * get_yith_gift_cards_discount
    *
    * @version 4.9.0
    * @since 4.9.0
    *
    * @param $cart
    * @param $discount
    */
    function get_yith_gift_cards_discount( $cart, $discount ) {
    $this->yith_gift_card_discount = $discount;
    }

    /**
    * get_order_minimum_amount_with_user_roles.
    *
    * @version 5.1.0
    * @since 2.5.3
    */
    function get_order_minimum_amount_with_user_roles() {
    $minimum = get_option( ‘wcj_order_minimum_amount’, 0 );
    $current_user_role = wcj_get_current_user_first_role();
    foreach ( wcj_get_user_roles() as $role_key => $role_data ) {
    if ( $role_key === $current_user_role ) {
    $order_minimum_amount_by_user_role = get_option( ‘wcj_order_minimum_amount_by_user_role_’ . $role_key, 0 );
    if ( $order_minimum_amount_by_user_role > 0 ) {
    $minimum = $order_minimum_amount_by_user_role;
    }
    break;
    }
    }
    // Multicurrency (Currency Switcher) module
    if ( WCJ()->modules[‘multicurrency’]->is_enabled() ) {
    $minimum = WCJ()->modules[‘multicurrency’]->change_price( $minimum, null );
    }
    // Price by country module
    if ( WCJ()->modules[‘price_by_country’]->is_enabled() ) {
    $minimum = WCJ()->modules[‘price_by_country’]->core->change_price( $minimum, null );
    }
    // WooCommerce Multilingual
    if ( ‘yes’ === get_option( ‘wcj_order_minimum_compatibility_wpml_multilingual’, ‘no’ ) ) {
    global $woocommerce_wpml;
    $minimum = ! empty( $woocommerce_wpml ) ? $woocommerce_wpml->multi_currency->prices->convert_price_amount( $minimum ) : $minimum;
    }

    return $minimum;
    }

    /**
    * get_cart_total_for_minimal_order_amount.
    *
    * @version 4.9.0
    * @since 2.5.5
    */
    function get_cart_total_for_minimal_order_amount() {
    if ( ! isset( WC()->cart ) ) {
    return 0;
    }
    WC()->cart->calculate_totals();
    $cart_total = WC()->cart->total;
    if ( ‘yes’ === get_option( ‘wcj_order_minimum_amount_exclude_shipping’, ‘no’ ) ) {
    $shipping_total = isset( WC()->cart->shipping_total ) ? WC()->cart->shipping_total : 0;
    $shipping_tax_total = isset( WC()->cart->shipping_tax_total ) ? WC()->cart->shipping_tax_total : 0;
    $cart_total -= ( $shipping_total + $shipping_tax_total );
    }
    if ( ‘yes’ === get_option( ‘wcj_order_minimum_amount_exclude_discounts’, ‘no’ ) ) {
    $cart_total += ( WC()->cart->get_cart_discount_total() + WC()->cart->get_cart_discount_tax_total() );
    }
    if (‘yes’ === get_option( ‘wcj_order_minimum_amount_exclude_yith_gift_card_discount’, ‘no’ ) ) {
    $cart_total += $this->yith_gift_card_discount;
    }
    return $cart_total;
    }

    /**
    * order_minimum_amount.
    *
    * @version 2.9.0
    * @todo wcj_order_minimum_amount_checkout_notice_type
    */
    function order_minimum_amount() {
    $minimum = $this->get_order_minimum_amount_with_user_roles();
    if ( 0 == $minimum ) {
    return;
    }
    $cart_total = $this->get_cart_total_for_minimal_order_amount();
    if ( $cart_total < $minimum ) {
    if ( is_cart() ) {
    if ( ‘yes’ === get_option( ‘wcj_order_minimum_amount_cart_notice_enabled’, ‘no’ ) ) {
    $notice_function = get_option( ‘wcj_order_minimum_amount_cart_notice_function’, ‘wc_print_notice’ );
    $notice_function(
    sprintf( apply_filters( ‘booster_option’, ‘You must have an order with a minimum of %s to place your order, your current order total is %s.’, get_option( ‘wcj_order_minimum_amount_cart_notice_message’ ) ),
    wc_price( $minimum ),
    wc_price( $cart_total )
    ),
    get_option( ‘wcj_order_minimum_amount_cart_notice_type’, ‘notice’ )
    );
    }
    } else {
    wc_add_notice(
    sprintf( apply_filters( ‘booster_option’, ‘You must have an order with a minimum of %s to place your order, your current order total is %s.’, get_option( ‘wcj_order_minimum_amount_error_message’ ) ),
    wc_price( $minimum ),
    wc_price( $cart_total )
    ),
    ‘error’
    );
    }
    }
    }

    /**
    * stop_from_seeing_checkout.
    *
    * @version 3.2.3
    * @todo (maybe) if ( is_admin() ) return;
    */
    function stop_from_seeing_checkout( $wp ) {
    global $woocommerce;
    if ( ! isset( $woocommerce ) || ! is_object( $woocommerce ) ) {
    return;
    }
    if ( ! isset( $woocommerce->cart ) || ! is_object( $woocommerce->cart ) ) {
    return;
    }
    if ( ! is_checkout() ) {
    return;
    }
    $minimum = $this->get_order_minimum_amount_with_user_roles();
    if ( 0 == $minimum ) {
    return;
    }
    $the_cart_total = $this->get_cart_total_for_minimal_order_amount();
    if ( 0 == $the_cart_total ) {
    return;
    }
    if ( $the_cart_total < $minimum ) {
    wp_safe_redirect( wc_get_cart_url() );
    exit;
    }
    }

    }

    endif;

    return new WCJ_Order_Min_Amount();

    Plugin Author pimwick

    (@pimwick)

    Our gift card plugin is compatible with the Order Minimum/Maximum Amount for WooCommerce plugin by Algoritmika Ltd, can you use that instead?

    Thread Starter mahadavid

    (@mahadavid)

    I’ll try, thanks for the tip.

    Alternatively, wondering if there’s an available function or variable we can reference to stick in this function (it’d be a hack for our installation that doesn’t currently use yith). something like
    if {there was a pw-gift card used}
    then {skip the yith stuff and return the pw-gift card amount}
    else {return the yith amount}

    /**
    * get_yith_gift_cards_discount
    *
    * @version 4.9.0
    * @since 4.9.0
    *
    * @param $cart
    * @param $discount
    */
    function get_yith_gift_cards_discount( $cart, $discount ) {
    $this->yith_gift_card_discount = $discount;
    }

    Thanks again for looking

    Thread Starter mahadavid

    (@mahadavid)

    That plugin worked okay, but I had to disable blocking people from going to the cart to make it work, (and didn’t want to spend the money on the gift card) so not 100% sure it did.

    As to looking for the code in the previous request, I think the Yith part of the code is only enabled on the pro version, so I wouldn’t be able to access it anyhow.

    Thanks for the support!

    Plugin Author pimwick

    (@pimwick)

    Glad to hear you got it sorted out, let us know if you need anything else. Best of luck with your store!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Using gift card brings balance below minimum’ is closed to new replies.