/** * Get the original price before any discounts are applied. * * @since 1.0 * * @param bool $format * * @return float|string */ public function get_original_price($format = false) { $base_price = $this->upgrade_product->get_feature('base-price'); if (!empty($this->variant_hash)) { $variants = $this->upgrade_product->get_feature('base-price', array('setting' => 'variants')); if (isset($variants[$this->variant_hash])) { $base_price = $variants[$this->variant_hash]['value']; } } return $format ? it_exchange_format_price($base_price) : $base_price; }
/** * Get information about the licensing add-on. */ public function info() { $settings = it_exchange_get_option('addon_itelic'); if ($settings['renewal-discount-type'] == 'percent') { $discount = $settings['renewal-discount-amount'] . '%'; } else { $discount = it_exchange_format_price($settings['renewal-discount-amount']); } $info = array('version' => ITELIC\Plugin::VERSION, 'online_software_enabled' => $settings['sell-online-software'] ? 'yes' : 'no', 'remote_activation_enabled' => $settings['enable-remote-activation'] ? 'yes' : 'no', 'remote_deactivation_enabled' => $settings['enable-remote-deactivation'] ? 'yes' : 'no', 'renewal_discounts_enabled' => $settings['enable-renewal-discounts'] ? 'yes' : 'no', 'renewal_discount' => $discount, 'renewal_discount_expiry' => sprintf("%d days", $settings['renewal-discount-expiry'])); $args = array('fields' => array_keys($info)); $formatter = new \WP_CLI\Formatter($args); $formatter->display_item($info); }
/** * Get fields for object. * * @param \ITELIC\Product $product * @param bool $raw * * @return array */ protected function get_fields_for_object(\ITELIC\Product $product, $raw = false) { $data = get_object_vars($product); $data['base-price'] = $product->get_feature('base-price'); if (!$raw) { $data['base-price'] = it_exchange_format_price($data['base-price']); } $base = $product->get_feature('licensing'); $data['online-software'] = $base['online-software'] ? 'yes' : 'no'; $data['version'] = $base['version']; $data['key-type'] = $base['key-type']; $data['update-file'] = ($p = get_post($base['update-file'])) ? $p->post_title : '-'; $data['variants-enabled'] = $base['enabled_variant_activations'] ? 'yes' : 'no'; if ($base['enabled_variant_activations']) { $data['limit'] = 'variant'; } else { $data['limit'] = $base['limit'] ? $base['limit'] : 'Unlimited'; } $data['changelog'] = $product->get_changelog(10); return $data; }
/** * Get the discounted price of this product. * * @since 1.0 * * @param bool $format * * @return float|string */ public function get_discount_price($format = false) { $price = $this->get_amount_paid(); switch ($this->get_type()) { case self::TYPE_FLAT: $price -= $this->get_amount(); break; case self::TYPE_PERCENT: $price -= $price * ($this->get_amount() / 100); break; } if ($format) { return it_exchange_format_price($price); } else { return $price; } }
/** * Get the price a customer can upgrade to for. * * @since 1.0 * * @param bool $format * * @return float|string */ public function get_upgrade_price($format = false) { $upgrade_price = $this->get_original_price() - $this->get_discount(); return $format ? it_exchange_format_price($upgrade_price) : $upgrade_price; }
/** * Get the revenue from this renewal. * * @since 1.0 * * @param bool $format * * @return float|string */ public function get_revenue($format = false) { if ($format) { return it_exchange_format_price($this->revenue); } return $this->revenue; }
/** * Get the total amount of the upgrade discount. * * @since 1.0 * * @param bool $format * * @return float|string */ public function get_discount($format = false) { return $format ? it_exchange_format_price($this->amount) : $this->amount; }