/** * Returns single instance of the class * * @since 1.0.0 */ public static function get_instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Prevent the current order to completed if the gift card code is no more valid */ public function woocommerce_after_checkout_validation($posted) { $gift_cards_used = WC()->cart->coupon_discount_amounts; if ($gift_cards_used) { foreach ($gift_cards_used as $code => $amount) { // Check if the code belong to a gift card and there is enough credit // to cover the amount requested. $gift = $this->gift_cards_instance->get_gift_card_by_code($code); if ($gift != null && !$gift->has_credit($amount)) { wc_add_notice(sprintf(__("The gift card identified by the code %s has no credit left.", "yith-woocommerce-gift-cards"), $code), "error"); } } } }
function yith_ywgc_init() { /** * Load text domain and start plugin */ load_plugin_textdomain('yith-woocommerce-gift-cards', false, dirname(plugin_basename(__FILE__)) . '/languages/'); YWGC_Plugin_FW_Loader::get_instance(); global $YWGC, $GIFTS; $GIFTS = YWGC_Gift_Cards::get_instance(); $YWGC = YITH_WooCommerce_Gift_Cards::get_instance(); }