id = $id; $this->init = $init; $this->settings = $settings; $this->load_methods(); } /** * Loads all payment methods from the database * * @since 3.0.0 */ public function load_methods() { global $wpdb; $has_subscriptions = false; if ( class_exists( '\WC_Subscriptions_Cart' ) ) { if ( \WC_Subscriptions_Cart::cart_contains_subscription() ) { $has_subscriptions = true; } } $methods = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . MAKECOMMERCE_TABLENAME ); if ( count( $methods ) ) { if ( is_admin() && $this->init == true && get_option( 'mc_banklinks_api_type' ) != get_option( 'mk_api_type', false ) ) { add_action( 'admin_notices', array( $this, 'banklinks_list_type_notice' ) ); } foreach ( $methods as $method ) { if ( $method->type == 'banklink'|| $method->type == 'other' ) { if ( !$has_subscriptions ) { $banklinks[] = $banklinks_grouped[$method->country][] = $method; } } elseif ( $method->type == 'card' ) { $cards[] = $method; } elseif( $method->type == 'payLater' ) { if ( !$has_subscriptions ) { $paylater[] = $paylater_grouped[$method->country][] = $method; } } } if ( isset( $this->settings['ui_chorder'] ) ) { if ( !$has_subscriptions && isset( $banklinks ) && isset( $banklinks_grouped ) ) { usort( $banklinks, array( $this, 'sort_banklinks' ) ); foreach( $banklinks_grouped as &$country ) { usort( $country, array( $this, 'sort_banklinks' ) ); } } } if ( !$has_subscriptions ) { if ( isset( $banklinks ) ) { $this->banklinks = $banklinks; } if ( isset( $banklinks_grouped ) ) { $this->banklinks_grouped = $banklinks_grouped; } if ( isset( $paylater ) ) { $this->paylater = $paylater; } if ( isset( $paylater_grouped ) ) { $this->paylater_grouped = $paylater_grouped; } } if ( isset( $cards ) ) { $this->cards = array_reverse( $cards ); } if ( is_admin() ) { remove_action( 'admin_notices', array( $this, 'empty_banklinks_notice' ), 30 ); } } elseif ( is_admin() && $this->init == true ) { add_action( 'admin_notices', array( $this, 'empty_banklinks_notice' ), 30 ); } } /** * Banklink sorting function * * @since 3.0.0 */ public function sort_banklinks( $a, $b ) { $order = array_map( 'trim', explode( ",", $this->settings['ui_chorder'] ) ); $posA = array_search( $a->name, $order ); $posB = array_search( $b->name, $order ); if ( $posA === $posB ) { return $a->id > $b->id ? 1 : -1; } if ( $posA === FALSE ) { return 1; } if ( $posB === FALSE ) { return -1; } return $posA > $posB ? 1 : -1; } /** * Notice for admin that banklinks are empty * * @since 3.0.0 */ public function empty_banklinks_notice() { ?>
customer ) { $customerCountry = strtolower( $woocommerce->customer->get_shipping_country() ); if ( array_key_exists( $customerCountry, $this->banklinks_grouped ) ) { return $customerCountry; } else { return 'other'; } } $localeToCountry = array( 'et' => 'ee', 'lv' => 'lv', 'lt' => 'lt', 'fi' => 'fi', ); $locale = \MakeCommerce\i18n::get_two_char_locale(); if ( array_key_exists( $local, $localeToCountry ) ) { return $localeToCountry[$locale]; } return key( $this->banklinks_grouped ); } /** * Show available payment methods in checkout * * @since 3.0.0 */ public function show_methods() { if ( !($this->settings['ui_mode'] == 'inline') ) { $this->hidden_select_box_payment_methods(); } $this->method_list(); $this->method_list_js(); if ( $this->settings['ui_open_by_default'] == 'yes' ) { \MakeCommerce::mc_enqueue_script( 'MC_DEFAULT_PM', dirname( __FILE__ ) . '/js/mc_default_pm.js', [ 'id' => $this->id ], [ 'jquery' ] ); } } /** * Display country selector for payment methods * * @since 3.0.1 */ private function method_list_countries() { //sort countries $this->sort_countries_list(); if ( ( empty( $this->settings['ui_widget_groupcountries'] ) || $this->settings['ui_widget_groupcountries'] == 'no' ) && ( !isset( $this->settings['ui_widget_countries_hidden'] ) || $this->settings['ui_widget_countries_hidden'] == 'no' ) ) { ?>'. _e( 'No payment methods for selected country' ,'wc_makecommerce_domain' ) .'
'; } } } } /** * Show list of credit cards * * @since 3.0.1 */ private function creditcard_list( $country ) { if ( $this->cards ) { echo ''; foreach ( $this->cards as $method ) { if ( $this->settings['ui_mode'] == 'inline' ) { $this->list_version_item( $method, true ); } else { $this->widget_version_item( $method, true ); } } } else if ( $country == 'other' ) { echo ''. _e( 'No payment methods for selected country' ,'wc_makecommerce_domain' ) .'
'; } } }