Beispiel #1
0
 /**
  * Get a tax rate.
  *
  * @param string $tax_class Tax class.
  * @param string $country A two-letter country code.
  * @param string $state
  * @return float Percentage tax rate.
  */
 protected function get_tax_rate($tax_class, $country, $state = '')
 {
     global $wpdb;
     $rates = array();
     $priorities = array();
     $location = ib_edu_get_location();
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE tax_class = %s AND country IN (\'\', %s, %s) AND state IN (\'\', %s, %s) ORDER BY priority ASC, rate_order ASC';
     $results = $wpdb->get_results($wpdb->prepare($sql, $tax_class, $location[0], $country, $location[1], $state));
     $inclusive = ib_edu_get_option('tax_inclusive', 'taxes');
     if (!$inclusive) {
         $inclusive = 'y';
     }
     $inc_rate = 0.0;
     $inc_priorities = array();
     foreach ($results as $row) {
         if ('y' == $inclusive && !in_array($row->priority, $inc_priorities) && ($location[0] == $row->country || '' == $row->country) && ($location[1] == $row->state || '' == $row->state)) {
             // Calculate inclusive tax rate.
             $inc_rate += $row->rate;
             $inc_priorities[] = $row->priority;
         }
         if (!in_array($row->priority, $priorities) && ($country == $row->country || '' == $row->country) && ($state == $row->state || '' == $row->state)) {
             // Select tax rates.
             $rates[] = $row;
             $priorities[] = $row->priority;
         }
     }
     if ($inc_rate) {
         $this->inclusive_rate = $inc_rate;
     }
     return array('inclusive' => $inc_rate, 'rates' => $rates);
 }
 /**
  * Output default user register form.
  *
  * @param WP_Error $errors
  * @param WP_Post $object
  */
 public static function register_form($errors, $object)
 {
     // Get current user.
     $user = wp_get_current_user();
     $error_codes = is_wp_error($errors) ? $errors->get_error_codes() : array();
     // Determine fields that can have multiple errors.
     $has_error = self::parse_register_errors($error_codes);
     // Setup form.
     require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php';
     $form = new IB_Educator_Form();
     $form->default_decorators();
     if (!$user->ID) {
         // Add account details group.
         $form->add_group(array('name' => 'account', 'label' => __('Create an Account', 'ibeducator')));
         // Set values.
         $form->set_value('account_username', isset($_POST['account_username']) ? $_POST['account_username'] : '');
         $form->set_value('account_email', isset($_POST['account_email']) ? $_POST['account_email'] : '');
         // Username.
         $form->add(array('type' => 'text', 'name' => 'account_username', 'container_id' => 'account-username-field', 'label' => __('Username', 'ibeducator'), 'id' => 'account-username', 'class' => isset($has_error['account_username']) ? 'error' : '', 'required' => true), 'account');
         // Email.
         $form->add(array('type' => 'text', 'name' => 'account_email', 'container_id' => 'account-email-field', 'label' => __('Email', 'ibeducator'), 'id' => 'account-email', 'class' => isset($has_error['account_email']) ? 'error' : '', 'required' => true), 'account');
     }
     if (ib_edu_collect_billing_data($object)) {
         // Add billing details group.
         $form->add_group(array('name' => 'billing', 'label' => __('Billing Details', 'ibeducator')));
         // Set values.
         $values = IB_Educator::get_instance()->get_billing_data($user->ID);
         if (empty($values['country'])) {
             $values['country'] = ib_edu_get_location('country');
         }
         if (empty($values['state'])) {
             $values['state'] = ib_edu_get_location('state');
         }
         $values['first_name'] = $user->ID ? $user->first_name : '';
         $values['last_name'] = $user->ID ? $user->last_name : '';
         foreach ($values as $key => $value) {
             $post_key = 'billing_' . $key;
             if (isset($_POST[$post_key])) {
                 $form->set_value($post_key, $_POST[$post_key]);
             } else {
                 $form->set_value($post_key, $value);
             }
         }
         // First Name.
         $form->add(array('type' => 'text', 'name' => 'billing_first_name', 'container_id' => 'billing-first-name-field', 'label' => __('First Name', 'ibeducator'), 'id' => 'billing-first-name', 'class' => in_array('billing_first_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Last Name.
         $form->add(array('type' => 'text', 'name' => 'billing_last_name', 'container_id' => 'billing-last-name-field', 'label' => __('Last Name', 'ibeducator'), 'id' => 'billing-last-name', 'class' => in_array('billing_last_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address.
         $form->add(array('type' => 'text', 'name' => 'billing_address', 'container_id' => 'billing-address-field', 'label' => __('Address', 'ibeducator'), 'id' => 'billing-address', 'class' => in_array('billing_address_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address Line 2.
         $form->add(array('type' => 'text', 'name' => 'billing_address_2', 'container_id' => 'billing-address-2-field', 'label' => __('Address Line 2', 'ibeducator'), 'id' => 'billing-address-2'), 'billing');
         // City.
         $form->add(array('type' => 'text', 'name' => 'billing_city', 'container_id' => 'billing-city-field', 'label' => __('City', 'ibeducator'), 'id' => 'billing-city', 'class' => in_array('billing_city_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         $edu_countries = IB_Educator_Countries::get_instance();
         // State.
         $state_field = array('name' => 'billing_state', 'container_id' => 'billing-state-field', 'label' => __('State / Province', 'ibeducator'), 'id' => 'billing-state', 'class' => in_array('billing_state_empty', $error_codes) ? 'error' : '', 'required' => true);
         $country = $form->get_value('billing_country');
         $states = $country ? $edu_countries->get_states($country) : null;
         if ($states) {
             $state_field['type'] = 'select';
             $state_field['options'] = array_merge(array('' => ' '), $states);
             unset($states);
         } else {
             $state_field['type'] = 'text';
         }
         $form->add($state_field, 'billing');
         // Postcode.
         $form->add(array('type' => 'text', 'name' => 'billing_postcode', 'container_id' => 'billing-postcode-field', 'label' => __('Postcode / Zip', 'ibeducator'), 'id' => 'billing-postcode', 'class' => in_array('billing_postcode_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Country.
         $form->add(array('type' => 'select', 'name' => 'billing_country', 'container_id' => 'billing-country-field', 'label' => __('Country', 'ibeducator'), 'id' => 'billing-country', 'class' => in_array('billing_country_empty', $error_codes) ? 'error' : '', 'required' => true, 'options' => array_merge(array('' => ' '), $edu_countries->get_countries())), 'billing');
     }
     $form->display();
 }
        $billing = IB_Educator::get_instance()->get_billing_data($user_id);
        // Get country.
        if (isset($_POST['billing_country'])) {
            $args['country'] = $_POST['billing_country'];
        } elseif (!empty($billing['country'])) {
            $args['country'] = $billing['country'];
        } else {
            $args['country'] = ib_edu_get_location('country');
        }
        // Get state.
        if (isset($_POST['billing_state'])) {
            $args['state'] = $_POST['billing_state'];
        } elseif (!empty($billing['state'])) {
            $args['state'] = $billing['state'];
        } else {
            $args['state'] = ib_edu_get_location('state');
        }
        // Get price.
        if ('ib_educator_course' == $post->post_type) {
            $args['price'] = ib_edu_get_course_price($post->ID);
        } elseif ('ib_edu_membership' == $post->post_type) {
            $args['price'] = Edr_Memberships::get_instance()->get_price($post->ID);
        }
        // Output payment summary.
        echo '<div id="edu-payment-info" class="edu-payment-info">' . Edr_StudentAccount::payment_info($post, $args) . '</div>';
        // Payment gateways.
        $gateways = IB_Educator_Main::get_gateways();
        ?>

				<?php 
        if ($args['price'] && !empty($gateways)) {