woocommerce-reseller-plugin/interweb-mz-reseller/includes/class-product.php

508 lines
27 KiB
PHP

<?php
if (!defined('ABSPATH')) {
exit;
}
/**
* WooCommerce products that the API fulfils: a "Fulfilment" tab in the product data box, the domain field
* on the product page, checks before the product goes to the cart, and the order item data.
*/
class INTERWEB_MZ_RESELLER_Product
{
const TYPES = array('domain_register', 'domain_transfer', 'plan', 'sms');
public static function type_names()
{
return array(
'' => __('Not fulfilled by the API', 'interweb-mz-reseller'),
'domain_register' => __('Domain registration', 'interweb-mz-reseller'),
'domain_transfer' => __('Domain transfer', 'interweb-mz-reseller'),
'plan' => __('Hosting or server plan', 'interweb-mz-reseller'),
'sms' => __('SMS credits', 'interweb-mz-reseller'),
);
}
public static function init()
{
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'tab'));
add_action('woocommerce_product_data_panels', array(__CLASS__, 'panel'));
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'save'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_assets'));
add_action('woocommerce_before_add_to_cart_button', array(__CLASS__, 'fields'));
add_filter('woocommerce_add_to_cart_validation', array(__CLASS__, 'validate'), 10, 3);
add_filter('woocommerce_add_cart_item_data', array(__CLASS__, 'cart_item_data'), 10, 2);
add_filter('woocommerce_get_item_data', array(__CLASS__, 'show_in_cart'), 10, 2);
add_action('woocommerce_checkout_create_order_line_item', array(__CLASS__, 'order_item'), 10, 4);
add_filter('woocommerce_is_sold_individually', array(__CLASS__, 'individually'), 10, 2);
add_filter('woocommerce_order_item_display_meta_key', array(__CLASS__, 'meta_label'), 10, 3);
add_filter('woocommerce_hidden_order_itemmeta', array(__CLASS__, 'hidden_meta'));
add_filter('woocommerce_product_add_to_cart_url', array(__CLASS__, 'loop_url'), 10, 2);
add_filter('woocommerce_product_add_to_cart_text', array(__CLASS__, 'loop_text'), 10, 2);
add_filter('woocommerce_product_supports', array(__CLASS__, 'no_ajax'), 10, 3);
// Domain search plugin of the same brand: its Register button can put the name in this cart.
add_filter('interweb_mz_domain_buy_url', array(__CLASS__, 'search_url'), 10, 3);
}
/* ---- Product meta ---- */
public static function type($product)
{
$product = is_numeric($product) ? wc_get_product($product) : $product;
if (!$product) {
return '';
}
$id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
$t = (string) get_post_meta($id, '_interweb_mz_reseller_type', true);
return in_array($t, self::TYPES, true) ? $t : '';
}
public static function meta($product, $key, $default = '')
{
$product = is_numeric($product) ? wc_get_product($product) : $product;
if (!$product) {
return $default;
}
$id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
$v = get_post_meta($id, '_interweb_mz_reseller_' . $key, true);
return $v === '' ? $default : $v;
}
public static function needs_domain($type)
{
return in_array($type, array('domain_register', 'domain_transfer'), true);
}
/* ---- Admin: Fulfilment tab ---- */
public static function tab($tabs)
{
$tabs['acrsl'] = array(
'label' => __('Fulfilment', 'interweb-mz-reseller'),
'target' => 'interweb_mz_reseller_product_data',
'class' => array(),
'priority' => 75,
);
return $tabs;
}
public static function admin_assets($hook)
{
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if (!$screen || $screen->post_type !== 'product') {
return;
}
wp_enqueue_style('interweb-mz-reseller-admin', INTERWEB_MZ_RESELLER_URL . 'assets/admin.css', array(), INTERWEB_MZ_RESELLER_VERSION);
wp_enqueue_script('interweb-mz-reseller-select', INTERWEB_MZ_RESELLER_URL . 'assets/select.js', array(), INTERWEB_MZ_RESELLER_VERSION, true);
wp_enqueue_script('interweb-mz-reseller-product', INTERWEB_MZ_RESELLER_URL . 'assets/product.js', array(), INTERWEB_MZ_RESELLER_VERSION, true);
}
public static function panel()
{
global $post;
$product = wc_get_product($post->ID);
$type = self::type($product);
echo '<div id="interweb_mz_reseller_product_data" class="panel woocommerce_options_panel interweb-mz-reseller-wrap interweb-mz-reseller-panel">';
if (INTERWEB_MZ_RESELLER_Settings::api_key() === '') {
echo '<p class="interweb-mz-reseller-error">' . esc_html__('Save the API key in Settings > Interweb Mozambique Reseller first.', 'interweb-mz-reseller') . '</p>';
}
echo '<p class="form-field"><label for="interweb_mz_reseller_type">' . esc_html__('The API fulfils it as', 'interweb-mz-reseller') . '</label>'
. INTERWEB_MZ_RESELLER_Admin::select('interweb_mz_reseller_type', self::type_names(), $type, 'interweb_mz_reseller_type') . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built only from escaped parts (plugin helpers escape every value).
echo '<div class="interweb-mz-reseller-only" data-for="domain_register domain_transfer">';
woocommerce_wp_text_input(array(
'id' => 'interweb_mz_reseller_tlds',
'label' => __('Allowed extensions', 'interweb-mz-reseller'),
'value' => (string) self::meta($product, 'tlds'),
'placeholder' => __('All', 'interweb-mz-reseller'),
'desc_tip' => true,
'description' => __('For example: .co.mz, .com. Empty accepts every extension the API sells.', 'interweb-mz-reseller'),
));
echo '</div>';
echo '<div class="interweb-mz-reseller-only" data-for="domain_register">';
woocommerce_wp_text_input(array(
'id' => 'interweb_mz_reseller_years',
'label' => __('Years', 'interweb-mz-reseller'),
'value' => (string) self::meta($product, 'years', '1'),
'type' => 'number',
'custom_attributes' => array('min' => 1, 'max' => 10),
));
woocommerce_wp_text_input(array(
'id' => 'interweb_mz_reseller_ns',
'label' => __('Nameservers', 'interweb-mz-reseller'),
'value' => (string) self::meta($product, 'ns'),
'placeholder' => __('Ours', 'interweb-mz-reseller'),
'desc_tip' => true,
'description' => __('Optional, 2 to 5, separated by commas. Empty uses the nameservers of the brand.', 'interweb-mz-reseller'),
));
echo '</div>';
echo '<div class="interweb-mz-reseller-only" data-for="plan">';
$plans = INTERWEB_MZ_RESELLER_Settings::api_key() !== '' ? INTERWEB_MZ_RESELLER_Catalog::plans() : array();
$plan_id = (int) self::meta($product, 'plan');
if (is_wp_error($plans)) {
echo '<p class="interweb-mz-reseller-error">' . esc_html($plans->get_error_message()) . '</p>';
$plans = array();
}
$opts = array('0' => __('Choose a plan', 'interweb-mz-reseller'));
$kinds = INTERWEB_MZ_RESELLER_Catalog::kinds();
foreach ($plans as $p) {
$opts[(string) $p['id']] = $kinds[$p['kind']][0] . ': ' . $p['name'];
}
echo '<p class="form-field"><label for="interweb_mz_reseller_plan">' . esc_html__('Plan', 'interweb-mz-reseller') . '</label>' . INTERWEB_MZ_RESELLER_Admin::select('interweb_mz_reseller_plan', $opts, (string) $plan_id, 'interweb_mz_reseller_plan') . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built only from escaped parts (plugin helpers escape every value).
$cycle = (string) self::meta($product, 'cycle', 'annually');
$cycles = INTERWEB_MZ_RESELLER_Catalog::cycles();
if ($plan_id && isset($plans[$plan_id])) {
$cycles = array_intersect_key($cycles, $plans[$plan_id]['prices']);
}
echo '<p class="form-field"><label for="interweb_mz_reseller_cycle">' . esc_html__('Billing cycle', 'interweb-mz-reseller') . '</label>' . INTERWEB_MZ_RESELLER_Admin::select('interweb_mz_reseller_cycle', $cycles, $cycle, 'interweb_mz_reseller_cycle') . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built only from escaped parts (plugin helpers escape every value).
if ($plan_id) {
$detail = INTERWEB_MZ_RESELLER_Catalog::plan($plan_id);
$chosen = (array) json_decode((string) self::meta($product, 'options', '{}'), true);
if (!is_wp_error($detail) && !empty($detail['config_options'])) {
foreach ($detail['config_options'] as $o) {
$c = array();
foreach ($o['choices'] as $ch) {
$c[(string) $ch['id']] = $ch['name'];
}
$cur = isset($chosen[$o['id']]) ? (string) $chosen[$o['id']] : (string) $o['default_choice_id'];
echo '<p class="form-field"><label for="interweb_mz_reseller_opt_' . (int) $o['id'] . '">' . esc_html($o['name']) . '</label>' . INTERWEB_MZ_RESELLER_Admin::select('interweb_mz_reseller_opt[' . (int) $o['id'] . ']', $c, $cur, 'interweb_mz_reseller_opt_' . (int) $o['id']) . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built only from escaped parts (plugin helpers escape every value).
}
} elseif (is_wp_error($detail)) {
echo '<p class="interweb-mz-reseller-error">' . esc_html($detail->get_error_message()) . '</p>';
}
if (!empty($detail['accepts_domain'])) {
woocommerce_wp_checkbox(array(
'id' => 'interweb_mz_reseller_ask_domain',
'label' => __('Ask for the domain', 'interweb-mz-reseller'),
'value' => self::meta($product, 'ask_domain', 'yes'),
'description' => __('The customer writes the site domain. It is used when the domain is in your account; otherwise the plan starts with a temporary address.', 'interweb-mz-reseller'),
));
}
} else {
echo '<p class="description interweb-mz-reseller-note">' . esc_html__('Choose the plan and update the product to see its options.', 'interweb-mz-reseller') . '</p>';
}
echo '</div>';
echo '<div class="interweb-mz-reseller-only" data-for="sms">';
woocommerce_wp_text_input(array(
'id' => 'interweb_mz_reseller_sms_qty',
'label' => __('Credits per unit', 'interweb-mz-reseller'),
'value' => (string) self::meta($product, 'sms_qty', '1000'),
'type' => 'number',
'custom_attributes' => array('min' => 1),
'desc_tip' => true,
'description' => __('Credits bought for each unit in the order. They go to your SMS balance; the plugin keeps the count for each customer.', 'interweb-mz-reseller'),
));
echo '</div>';
echo '<div class="interweb-mz-reseller-only" data-for="domain_register domain_transfer plan">';
woocommerce_wp_text_input(array(
'id' => 'interweb_mz_reseller_renew_price',
'label' => __('Renewal price', 'interweb-mz-reseller') . ' (' . get_woocommerce_currency_symbol() . ')',
'value' => (string) self::meta($product, 'renew_price'),
'data_type' => 'price',
'placeholder' => __('Same as the product price', 'interweb-mz-reseller'),
'desc_tip' => true,
'description' => __('What the customer pays for each renewal.', 'interweb-mz-reseller'),
));
echo '</div>';
$cost = self::cost_line($product);
if ($cost !== '') {
echo '<p class="interweb-mz-reseller-cost">' . wp_kses($cost, array('strong' => array(), 'span' => array('class' => array()))) . '</p>';
}
echo '</div>';
}
/** Your API price next to the WooCommerce price, with a warning when you would sell below it. */
public static function cost_line($product)
{
if (!$product || INTERWEB_MZ_RESELLER_Settings::api_key() === '') {
return '';
}
$type = self::type($product);
$c = null;
if ($type === 'plan' && (int) self::meta($product, 'plan')) {
$c = INTERWEB_MZ_RESELLER_Catalog::plan_cost((int) self::meta($product, 'plan'), (string) self::meta($product, 'cycle', 'annually'), (array) json_decode((string) self::meta($product, 'options', '{}'), true));
} elseif ($type === 'sms') {
$c = INTERWEB_MZ_RESELLER_Catalog::sms_cost((int) self::meta($product, 'sms_qty', '1000'));
} elseif ($type === 'domain_register') {
$exts = self::allowed_tlds($product);
if (count($exts) === 1) {
$c = INTERWEB_MZ_RESELLER_Catalog::tld_cost($exts[0], 'register', max(1, (int) self::meta($product, 'years', '1')));
}
}
if (!$c) {
return '';
}
$line = sprintf(
/* translators: %s: amount */
__('Your API price: %s.', 'interweb-mz-reseller'),
'<strong>' . esc_html(INTERWEB_MZ_RESELLER_Admin::money($c['cost'], $c['currency'])) . '</strong>'
);
$price = (float) $product->get_price();
if ($price > 0 && $c['currency'] === get_woocommerce_currency() && $price < $c['cost']) {
$line .= ' <span class="interweb-mz-reseller-error">' . esc_html__('The product price is lower than your API price.', 'interweb-mz-reseller') . '</span>';
} elseif ($c['currency'] !== get_woocommerce_currency()) {
$line .= ' <span class="description">' . esc_html(sprintf(
/* translators: 1: API currency, 2: WooCommerce currency */
__('The API uses %1$s and WooCommerce uses %2$s: compare them yourself.', 'interweb-mz-reseller'),
$c['currency'],
get_woocommerce_currency()
)) . '</span>';
}
return $line;
}
public static function save($product)
{
$p = wp_unslash($_POST);
$type = isset($p['interweb_mz_reseller_type']) && in_array($p['interweb_mz_reseller_type'], self::TYPES, true) ? $p['interweb_mz_reseller_type'] : '';
$product->update_meta_data('_interweb_mz_reseller_type', $type);
if ($type === '') {
return;
}
$tlds = array();
foreach (preg_split('/[\s,]+/', strtolower(isset($p['interweb_mz_reseller_tlds']) ? (string) $p['interweb_mz_reseller_tlds'] : '')) as $e) {
$e = '.' . ltrim(preg_replace('/[^a-z0-9.\-]/', '', $e), '.');
if (strlen($e) > 2) {
$tlds[] = $e;
}
}
$product->update_meta_data('_interweb_mz_reseller_tlds', implode(', ', array_unique($tlds)));
$product->update_meta_data('_interweb_mz_reseller_years', (string) min(10, max(1, (int) (isset($p['interweb_mz_reseller_years']) ? $p['interweb_mz_reseller_years'] : 1))));
$ns = array();
foreach (preg_split('/[\s,]+/', strtolower(isset($p['interweb_mz_reseller_ns']) ? (string) $p['interweb_mz_reseller_ns'] : '')) as $n) {
$n = preg_replace('/[^a-z0-9.\-]/', '', $n);
if ($n !== '' && strpos($n, '.') !== false) {
$ns[] = $n;
}
}
$product->update_meta_data('_interweb_mz_reseller_ns', implode(', ', array_slice($ns, 0, 5)));
$product->update_meta_data('_interweb_mz_reseller_plan', (string) (int) (isset($p['interweb_mz_reseller_plan']) ? $p['interweb_mz_reseller_plan'] : 0));
$product->update_meta_data('_interweb_mz_reseller_cycle', isset($p['interweb_mz_reseller_cycle']) && array_key_exists($p['interweb_mz_reseller_cycle'], INTERWEB_MZ_RESELLER_Catalog::cycles()) ? $p['interweb_mz_reseller_cycle'] : 'annually');
$opts = array();
foreach ((array) (isset($p['interweb_mz_reseller_opt']) ? $p['interweb_mz_reseller_opt'] : array()) as $k => $v) {
$opts[(int) $k] = (int) $v;
}
$product->update_meta_data('_interweb_mz_reseller_options', wp_json_encode((object) $opts));
$product->update_meta_data('_interweb_mz_reseller_ask_domain', empty($p['interweb_mz_reseller_ask_domain']) ? 'no' : 'yes');
$product->update_meta_data('_interweb_mz_reseller_sms_qty', (string) max(1, (int) (isset($p['interweb_mz_reseller_sms_qty']) ? $p['interweb_mz_reseller_sms_qty'] : 1000)));
$rp = isset($p['interweb_mz_reseller_renew_price']) ? wc_format_decimal($p['interweb_mz_reseller_renew_price']) : '';
$product->update_meta_data('_interweb_mz_reseller_renew_price', $rp === '' ? '' : (string) $rp);
// Products fulfilled by the API are services: no shipping.
$product->set_virtual(true);
}
/* ---- Product page ---- */
public static function allowed_tlds($product)
{
$csv = (string) self::meta($product, 'tlds');
return $csv === '' ? array() : array_values(array_filter(array_map('trim', explode(',', $csv))));
}
public static function asks_domain($product)
{
$type = self::type($product);
return self::needs_domain($type) || ($type === 'plan' && self::meta($product, 'ask_domain', 'no') === 'yes');
}
public static function fields()
{
global $product;
if (!$product || !self::asks_domain($product)) {
return;
}
$type = self::type($product);
$value = isset($_REQUEST['interweb_mz_reseller_domain']) ? self::clean_domain(wp_unslash($_REQUEST['interweb_mz_reseller_domain'])) : '';
$exts = self::allowed_tlds($product);
wp_enqueue_style('interweb-mz-reseller-front', INTERWEB_MZ_RESELLER_URL . 'assets/front.css', array(), INTERWEB_MZ_RESELLER_VERSION);
echo '<div class="interweb-mz-reseller-fields">';
echo '<p class="interweb-mz-reseller-field"><label for="interweb_mz_reseller_domain">' . esc_html($type === 'plan' ? __('Site domain (optional)', 'interweb-mz-reseller') : __('Domain name', 'interweb-mz-reseller')) . '</label>';
echo '<input type="text" id="interweb_mz_reseller_domain" name="interweb_mz_reseller_domain" value="' . esc_attr($value) . '" maxlength="120" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="' . esc_attr('mycompany' . ($exts ? $exts[0] : '.com')) . '"' . ($type === 'plan' ? '' : ' required') . '>';
if ($exts) {
echo '<small>' . esc_html(sprintf(
/* translators: %s: list of extensions */
__('Extensions: %s', 'interweb-mz-reseller'),
implode(' ', $exts)
)) . '</small>';
}
echo '</p>';
if ($type === 'domain_transfer') {
echo '<p class="interweb-mz-reseller-field"><label for="interweb_mz_reseller_epp">' . esc_html__('Transfer code (EPP)', 'interweb-mz-reseller') . '</label>';
echo '<input type="text" id="interweb_mz_reseller_epp" name="interweb_mz_reseller_epp" maxlength="120" autocomplete="off" spellcheck="false" required>';
echo '<small>' . esc_html__('Ask the company where the domain is now. The domain must be unlocked.', 'interweb-mz-reseller') . '</small></p>';
}
echo '</div>';
}
public static function clean_domain($q)
{
$q = strtolower(trim((string) $q));
$q = preg_replace('#^[a-z]+://#', '', $q);
$q = preg_replace('#^www\.#', '', $q);
$q = preg_replace('#[/?\#].*$#', '', $q);
$q = preg_replace('/[^a-z0-9.\-]/', '', $q);
return trim($q, '.-');
}
public static function validate($passed, $product_id, $qty)
{
$product = wc_get_product(isset($_REQUEST['variation_id']) && (int) $_REQUEST['variation_id'] ? (int) $_REQUEST['variation_id'] : $product_id);
if (!$product || !self::asks_domain($product)) {
return $passed;
}
$type = self::type($product);
$d = isset($_REQUEST['interweb_mz_reseller_domain']) ? self::clean_domain(wp_unslash($_REQUEST['interweb_mz_reseller_domain'])) : '';
if ($d === '' && $type === 'plan') {
return $passed;
}
if (!preg_match('/^[a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?(\.[a-z0-9\-]{2,})+$/', $d)) {
wc_add_notice(__('Write a valid domain name, for example mycompany.com.', 'interweb-mz-reseller'), 'error');
return false;
}
$exts = self::allowed_tlds($product);
if ($exts && self::needs_domain($type)) {
$ok = false;
foreach ($exts as $e) {
if (substr($d, -strlen($e)) === $e && strlen($d) > strlen($e)) {
$ok = true;
}
}
if (!$ok) {
wc_add_notice(sprintf(
/* translators: %s: list of extensions */
__('This product only takes these extensions: %s', 'interweb-mz-reseller'),
implode(' ', $exts)
), 'error');
return false;
}
}
if ($type === 'domain_transfer') {
$epp = isset($_REQUEST['interweb_mz_reseller_epp']) ? trim((string) wp_unslash($_REQUEST['interweb_mz_reseller_epp'])) : '';
if ($epp === '') {
wc_add_notice(__('Write the transfer code (EPP) of the domain.', 'interweb-mz-reseller'), 'error');
return false;
}
}
if ($type === 'domain_register') {
$res = INTERWEB_MZ_RESELLER_Api::request('GET', '/v1/domains/availability', null, array('query' => array('domain' => $d), 'timeout' => 20));
if (is_wp_error($res)) {
INTERWEB_MZ_RESELLER_Log::add('cart', false, $res->get_error_message(), array('domain' => $d));
wc_add_notice(__('We could not confirm that this name is free right now. Please try again in a moment.', 'interweb-mz-reseller'), 'error');
return false;
}
$a = $res['data'];
if (!empty($a['portal_only'])) {
wc_add_notice(__('This name needs extra steps and cannot be ordered here. Please contact us.', 'interweb-mz-reseller'), 'error');
return false;
}
if (empty($a['available'])) {
wc_add_notice(sprintf(
/* translators: %s: domain name */
__('%s is not available for registration.', 'interweb-mz-reseller'),
$d
), 'error');
return false;
}
}
return $passed;
}
public static function cart_item_data($data, $product_id)
{
if (isset($_REQUEST['interweb_mz_reseller_domain'])) {
$d = self::clean_domain(wp_unslash($_REQUEST['interweb_mz_reseller_domain']));
if ($d !== '') {
$data['interweb_mz_reseller_domain'] = $d;
}
}
if (isset($_REQUEST['interweb_mz_reseller_epp'])) {
$epp = sanitize_text_field(wp_unslash($_REQUEST['interweb_mz_reseller_epp']));
if ($epp !== '') {
$data['interweb_mz_reseller_epp'] = $epp;
}
}
if (!empty($data['interweb_mz_reseller_domain'])) {
$data['interweb_mz_reseller_key'] = md5($data['interweb_mz_reseller_domain'] . microtime());
}
return $data;
}
public static function show_in_cart($item_data, $cart_item)
{
if (!empty($cart_item['interweb_mz_reseller_domain'])) {
$item_data[] = array('key' => __('Domain', 'interweb-mz-reseller'), 'value' => esc_html($cart_item['interweb_mz_reseller_domain']));
}
return $item_data;
}
public static function order_item($item, $cart_key, $values, $order)
{
$product = $item->get_product();
$type = self::type($product);
if ($type === '') {
return;
}
$item->add_meta_data('_interweb_mz_reseller_type', $type, true);
if (!empty($values['interweb_mz_reseller_domain'])) {
$item->add_meta_data('interweb_mz_reseller_domain', $values['interweb_mz_reseller_domain'], true);
}
if (!empty($values['interweb_mz_reseller_epp'])) {
$item->add_meta_data('_interweb_mz_reseller_epp', $values['interweb_mz_reseller_epp'], true);
}
$item->add_meta_data('_interweb_mz_reseller_state', 'new', true);
$order->update_meta_data('_interweb_mz_reseller_has_items', 'yes');
}
public static function meta_label($display_key, $meta, $item)
{
return $meta->key === 'interweb_mz_reseller_domain' ? __('Domain', 'interweb-mz-reseller') : $display_key;
}
public static function hidden_meta($keys)
{
return array_merge($keys, array('_interweb_mz_reseller_type', '_interweb_mz_reseller_epp', '_interweb_mz_reseller_state', '_interweb_mz_reseller_action', '_interweb_mz_reseller_result', '_interweb_mz_reseller_tries', '_interweb_mz_reseller_service', '_interweb_mz_reseller_status', '_interweb_mz_reseller_expires', '_interweb_mz_reseller_renew_of', '_interweb_mz_reseller_reminded', '_interweb_mz_reseller_error', '_interweb_mz_reseller_sim', '_interweb_mz_reseller_years', '_interweb_mz_reseller_site', '_interweb_mz_reseller_invoice', '_interweb_mz_reseller_renewals', '_interweb_mz_reseller_round', '_interweb_mz_reseller_renew_open'));
}
public static function individually($yes, $product)
{
$type = self::type($product);
return ($type !== '' && $type !== 'sms') ? true : $yes;
}
/** Products that need a domain cannot go to the cart from the product list: the button opens the product page. */
public static function loop_url($url, $product)
{
return self::asks_domain($product) && self::needs_domain(self::type($product)) ? get_permalink($product->get_id()) : $url;
}
public static function loop_text($text, $product)
{
return self::asks_domain($product) && self::needs_domain(self::type($product)) ? __('Choose the domain', 'interweb-mz-reseller') : $text;
}
public static function no_ajax($supports, $feature, $product)
{
if ($feature === 'ajax_add_to_cart' && self::needs_domain(self::type($product))) {
return false;
}
return $supports;
}
/** Register button of the domain search: straight to the cart; transfer: the product page, for the code. */
public static function search_url($url, $domain, $action)
{
$pid = (int) INTERWEB_MZ_RESELLER_Settings::get($action === 'transfer' ? 'transfer_product' : 'register_product');
if (!$pid || !wc_get_product($pid)) {
return $url;
}
if ($action === 'transfer') {
return add_query_arg('interweb_mz_reseller_domain', rawurlencode($domain), get_permalink($pid));
}
return add_query_arg(array('add-to-cart' => $pid, 'interweb_mz_reseller_domain' => rawurlencode($domain)), wc_get_cart_url());
}
}