get_settings(); $notify_on_atc = !isset($settings['notify_on_add_to_cart']) || $settings['notify_on_add_to_cart'] === 'yes'; if ($notify_on_atc) { if ( ! defined( 'AIEO_RUNTIME_OWNS_AJAX' ) ) { add_action('woocommerce_add_to_cart', array($this, 'notify_on_add_to_cart'), 20, 6); } add_action('woocommerce_after_add_to_cart_form', array($this, 'render_product_page_notice')); } } if ( ! defined( 'AIEO_RUNTIME_OWNS_AJAX' ) ) { add_action('woocommerce_cart_calculate_fees', array($this, 'apply_cod_fee_to_cart'), 11, 1); add_filter('woocommerce_available_payment_gateways', array($this, 'force_cod_visible_when_aieo_enabled'), 999); } add_action('woocommerce_admin_order_data_after_billing_address', array($this, 'apply_cod_fee_admin'), 10, 1); add_action('wp_footer', array($this, 'output_cod_refresh_js')); add_action('woocommerce_blocks_loaded', array($this, 'maybe_register_cod_for_blocks')); } public function render_subtab() { $paged = isset($_GET['paged']) ? max(1, absint($_GET['paged'])) : 1; $this->render_unified_rules_section(); rooster_admin_band_open(array('cols' => 2, 'min' => 35)); $this->render_template('free-shipping.php', array( 'settings' => $this->get_settings(), 'exclusions' => $this->fetch_exclusions(100, $paged), 'exclusion_count' => $this->count_exclusions(), 'per_page' => 100, 'current_page' => $paged, )); $this->render_cod_card(); do_action('aieo_dmm_free_shipping_after_cod_card'); rooster_admin_band_close(); } private function render_cod_card() { $settings = $this->get_settings(true); $hint = self::i18n_hints(); $aieo_fs_cur = function_exists('get_woocommerce_currency_symbol') ? html_entity_decode(get_woocommerce_currency_symbol(), ENT_QUOTES | ENT_HTML5, 'UTF-8') : '€'; $aieo_fs_form = 'aieo-card-free-shipping-cash-on-delivery-form'; $aieo_fs_id = static function ($name) { return 'aieo-fs-' . str_replace('_', '-', $name); }; $aieo_fs_row = static function ($name, $label, $control, $help = '') use ($aieo_fs_id) { $field = array('id' => $aieo_fs_id($name), 'label' => $label, 'control' => $control); if ('' !== $help) { $field['help'] = $help; } return \Rooster\Admin\Ui::field_row($field); }; $aieo_fs_switch = static function ($name, $on, $text) use ($aieo_fs_id) { return \Rooster\Admin\Ui::toggle($name, $on, array('id' => $aieo_fs_id($name), 'hidden' => false, 'label' => $text)); }; list($aieo_fs_open, $aieo_fs_close) = AIEO_DMM_UI::card(array( 'anchor' => 'free-shipping-cash-on-delivery', 'icon' => 'banknote', 'title' => __('Cash on Delivery', 'ai-eshop-optimizer'), 'description' => __('Adds a fee to the order total when the customer picks the Cash on Delivery payment method at checkout. The fee is recalculated whenever the cart total or payment method changes (mini-cart qty changes included).', 'ai-eshop-optimizer'), 'footer' => \Rooster\Admin\States::save_button($aieo_fs_form, array('label' => __('Save COD settings', 'ai-eshop-optimizer'))), 'col' => 2, )); echo $aieo_fs_open; $aieo_fs_fields = $aieo_fs_row('cod_enabled', __('Enable COD fee', 'ai-eshop-optimizer'), $aieo_fs_switch('cod_enabled', $settings['cod_enabled'] === 'yes', __('Add a fee when the customer pays with Cash on Delivery', 'ai-eshop-optimizer'))); $aieo_fs_fields .= $aieo_fs_row('cod_fee', __('Fee amount', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('cod_fee', (string) $settings['cod_fee'], array('id' => $aieo_fs_id('cod_fee'), 'type' => 'number', 'step' => 'any', 'min' => '0', 'short' => true, 'unit' => $aieo_fs_cur)), __('In your shop currency. A typical cash-on-delivery fee is €1.50–€2.50.', 'ai-eshop-optimizer')); $aieo_fs_fields .= $aieo_fs_row('cod_label', __('Fee label', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('cod_label', (string) $settings['cod_label'], array('id' => $aieo_fs_id('cod_label'), 'medium' => true, 'maxlength' => '100', 'placeholder' => $hint['cod_label'])), __('Shown to the customer on cart/checkout/order — also used to detect duplicate fees so we never add it twice.', 'ai-eshop-optimizer')); $aieo_fs_fields .= $aieo_fs_row('cod_taxable', __('Taxable', 'ai-eshop-optimizer'), $aieo_fs_switch('cod_taxable', $settings['cod_taxable'] === 'yes', __('Apply tax to the COD fee', 'ai-eshop-optimizer'))); $aieo_fs_fields .= $aieo_fs_row('cod_gateway_slug', __('Payment gateway slug', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('cod_gateway_slug', (string) $settings['cod_gateway_slug'], array('id' => $aieo_fs_id('cod_gateway_slug'), 'short' => true, 'maxlength' => '50')), __('WooCommerce payment-method ID that triggers this fee. Default "cod" matches WooCommerce\'s built-in Cash on Delivery gateway.', 'ai-eshop-optimizer')); ob_start(); do_action('aieo_dmm_cod_card_after_fee_label', $settings); $aieo_fs_fields .= trim((string) ob_get_clean()); $aieo_fs_html = '
wp_aieo_dmm_offers',
'cost = 0'
);
echo \Rooster\Admin\Guidance::text('', 'guidance', array('html' => $aieo_fs_intro, 'question' => __('When do these rules apply?', 'ai-eshop-optimizer')));
?>
'free-shipping-existing-rules',
'icon' => 'list',
'title' => __('Existing rules', 'ai-eshop-optimizer'),
'description' => __('The free-shipping rules you have saved; edit one to change its targeting or switch it off.', 'ai-eshop-optimizer'),
));
echo $aieo_fs_open;
?>
__('No unified rules yet. Create one above.', 'ai-eshop-optimizer'))); ?>
'success', 'scheduled' => 'warning', 'ended' => 'mono', 'off' => 'mono');
$aieo_fs_scopes = array(
'cart_total' => __('Whole cart total', 'ai-eshop-optimizer'),
'targeted' => __('Subtotal of matching items only', 'ai-eshop-optimizer'),
);
$aieo_fs_actions = array(
'force_free' => __('Force every shipping rate to free', 'ai-eshop-optimizer'),
'force_free_first' => __('Force only the cheapest rate to free', 'ai-eshop-optimizer'),
);
$aieo_fs_rows = array();
$aieo_fs_ask = AIEO_DMM_Offer_Forms::edit_asked();
$aieo_fs_asked = null;
foreach ($rules as $r) {
$aieo_fs_edit = AIEO_DMM_Offer_Forms::edit_window($r) + $this->edit_payload($r) + array('campaign_id' => (int) ($r['campaign_id'] ?? 0), 'priority' => (int) ($r['priority'] ?? 100));
$aieo_fs_state = !empty($r['enabled']) ? AIEO_DMM_Schedule::state_for($aieo_fs_edit['date_from'], $aieo_fs_edit['date_to'], $r) : 'off';
if ($aieo_fs_ask > 0 && $aieo_fs_ask === (int) $r['id']) {
$aieo_fs_asked = $aieo_fs_edit;
}
$aieo_fs_min = (float) $r['min_subtotal'];
$aieo_fs_kept = AIEO_DMM_Offer_Forms::kept_here($r);
$aieo_fs_none = AIEO_DMM_Offer_Forms::targeting_of($r, $r)['_said'] ? '' : AIEO_DMM_Offer_Forms::NOT_SAID;
$aieo_fs_rows[] = array(
'_id' => (int) $r['id'],
'_name' => (string) $r['label'],
'label' => array('title' => (string) $r['label'], 'sub' => '#' . (int) $r['id'] . ($aieo_fs_kept ? ' · ' . AIEO_DMM_Offer_Forms::kept_here_label() : '')),
'brands' => '' !== $aieo_fs_none ? $aieo_fs_none : self::names_summary($aieo_fs_edit['brand_term_names'], $aieo_fs_any),
'categories' => '' !== $aieo_fs_none ? $aieo_fs_none : self::names_summary($aieo_fs_edit['category_term_names'], $aieo_fs_any),
'needs' => '' !== $aieo_fs_none ? $aieo_fs_none : self::names_summary($aieo_fs_edit['need_term_names'], $aieo_fs_any),
'products' => '' !== $aieo_fs_none ? $aieo_fs_none : self::names_summary(wp_list_pluck($aieo_fs_edit['product_products'], 'text'), $aieo_fs_any),
'op' => '' !== $aieo_fs_none ? $aieo_fs_none : $aieo_fs_edit['rule_operator'],
'threshold' => '' !== $aieo_fs_none ? array('title' => $aieo_fs_none, 'sub' => '') : array(
'title' => html_entity_decode(wp_strip_all_tags(wc_price($aieo_fs_min)), ENT_QUOTES, 'UTF-8'),
'sub' => $aieo_fs_min > 0 ? $aieo_fs_scopes[$aieo_fs_edit['min_subtotal_scope']] : '',
),
'action' => $aieo_fs_actions[$aieo_fs_edit['action_kind']],
'window' => AIEO_DMM_Schedule::window_label_for($aieo_fs_edit['date_from'], $aieo_fs_edit['date_to'], $r),
'state' => array(
'label' => 'off' === $aieo_fs_state ? __('Disabled', 'ai-eshop-optimizer') : AIEO_DMM_Schedule::state_label($aieo_fs_state),
'tone' => $aieo_fs_tones[$aieo_fs_state],
),
'enabled' => (int) $r['enabled'] ? 'yes' : 'no',
'actions' => array(
array(
'label' => __('Edit', 'ai-eshop-optimizer'),
'attrs' => array(
'data-aieo-fs-edit' => '1',
'data-rule' => (string) wp_json_encode($aieo_fs_edit),
),
),
array(
'label' => __('Delete', 'ai-eshop-optimizer'),
'destructive' => true,
'attrs' => array(
'data-aieo-delete-row' => '1',
'data-action' => 'aieo_dmm_free_shipping_delete_rule',
'data-row' => (int) $r['id'],
),
),
),
);
}
echo \Rooster\Admin\Ui::table(
array(
array('key' => 'label', 'label' => __('Label', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'brands', 'label' => __('Brands', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'categories', 'label' => __('Categories', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'needs', 'label' => __('Needs', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'products', 'label' => __('Products', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'op', 'label' => __('Op', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'threshold', 'label' => __('Threshold', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'action', 'label' => __('Action', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'window', 'label' => __('Schedule', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'state', 'label' => __('State', 'ai-eshop-optimizer'), 'type' => 'status'),
array('key' => 'enabled', 'label' => __('Enabled', 'ai-eshop-optimizer'), 'type' => 'boolean'),
array('key' => 'actions', 'label' => __('Actions', 'ai-eshop-optimizer'), 'type' => 'actions'),
),
$aieo_fs_rows,
array('id' => 'aieo-free-shipping-rules', 'caption' => esc_html__('Existing rules', 'ai-eshop-optimizer'), 'scroll' => true)
);
?>
name, ENT_QUOTES | ENT_HTML5, 'UTF-8') : ('#' . (int) $tid);
}
return $out;
};
$patterns = static function ($raw) {
$list = is_string($raw) ? json_decode($raw, true) : $raw;
return AIEO_DMM_Pattern_Match::parse(is_array($list) ? $list : array());
};
$json = static function ($raw) {
$value = is_string($raw) ? json_decode($raw, true) : $raw;
return is_array($value) ? $value : array();
};
$brands = self::id_list($row['brand_term_ids'] ?? '');
$cats = self::id_list($row['category_term_ids'] ?? '');
$needs = self::id_list($row['need_term_ids'] ?? '');
$ex_brands = self::id_list($row['excluded_brand_ids'] ?? '');
$ex_cats = self::id_list($row['excluded_category_ids'] ?? '');
$ex_needs = self::id_list($row['excluded_need_ids'] ?? '');
$payload = $json($row['payload'] ?? '');
$display = $json($row['display'] ?? '');
return array(
'id' => isset($row['id']) ? (int) $row['id'] : 0,
'label' => (string) ($row['label'] ?? ''),
'brand_term_ids' => $brands,
'brand_term_names' => $names($brands),
'category_term_ids' => $cats,
'category_term_names' => $names($cats),
'need_term_ids' => $needs,
'need_term_names' => $names($needs),
'excluded_brand_ids' => $ex_brands,
'excluded_brand_names' => $names($ex_brands),
'excluded_category_ids' => $ex_cats,
'excluded_category_names' => $names($ex_cats),
'excluded_need_ids' => $ex_needs,
'excluded_need_names' => $names($ex_needs),
'product_products' => AIEO_DMM_Product_Picker::hydrate_ids(self::id_list($row['product_ids'] ?? '')),
'excluded_products' => AIEO_DMM_Product_Picker::hydrate_ids(self::id_list($row['excluded_product_ids'] ?? '')),
'code_patterns' => $patterns($row['code_patterns'] ?? array()),
'excluded_code_patterns' => $patterns($row['excluded_code_patterns'] ?? array()),
'rule_operator' => (isset($row['rule_operator']) && 'OR' === strtoupper((string) $row['rule_operator'])) ? 'OR' : 'AND',
'date_from' => AIEO_DMM_Schedule::clean_date($row['start_date'] ?? ''),
'date_to' => AIEO_DMM_Schedule::clean_date($row['end_date'] ?? ''),
'enabled' => !empty($row['enabled']) ? 1 : 0,
'min_subtotal' => isset($row['min_subtotal']) ? (float) $row['min_subtotal'] : 0.0,
'min_subtotal_scope' => (isset($row['min_subtotal_scope']) && 'targeted' === $row['min_subtotal_scope']) ? 'targeted' : 'cart_total',
'action_kind' => (isset($payload['action']) && 'force_free_first' === $payload['action']) ? 'force_free_first' : 'force_free',
'badge_label' => AIEO_DMM_Offer_Texts::standing_label(array(), is_array($display) ? $display : array()),
);
}
private static function id_list($raw) {
if (is_string($raw)) {
$raw = json_decode($raw, true);
}
return is_array($raw) ? array_values(array_filter(array_map('intval', $raw))) : array();
}
private static function names_summary(array $names, $none) {
$names = array_values(array_filter(array_map('strval', $names), 'strlen'));
if (empty($names)) {
return (string) $none;
}
$shown = array_slice($names, 0, 3);
$more = count($names) - count($shown);
$text = implode(', ', $shown);
return $more > 0 ? sprintf(__('%1$s +%2$d', 'ai-eshop-optimizer'), $text, $more) : $text;
}
public static function badge_family_label() {
$family = class_exists('AIEO_DMM_Badges') ? AIEO_DMM_Badges::get_family('free_shipping') : null;
$label = (is_array($family) && isset($family['label'])) ? trim((string) $family['label']) : '';
return '' !== $label ? $label : __('Free delivery', 'ai-eshop-optimizer');
}
public function render_archive_badge() {
global $product;
if (!$product || !is_a($product, 'WC_Product')) { return; }
if (class_exists('AIEO_DMM_Badge_Renderer') && AIEO_DMM_Badge_Renderer::picture_carries($product->get_id())) { return; }
echo $this->archive_badge_html($product);
}
public function archive_badge_html($product) {
if (class_exists('AIEO_DMM_Badge_Renderer') && AIEO_DMM_Badge_Renderer::is_enabled()) { return ''; }
if (!$product || !is_a($product, 'WC_Product')) { return ''; }
if (!class_exists('AIEO_DMM_Free_Shipping_Rules') || !AIEO_DMM_Free_Shipping_Rules::has_targeted()) { return ''; }
$rule = AIEO_DMM_Free_Shipping_Rules::covering_rule($product);
if (!is_array($rule)) { return ''; }
$family = class_exists('AIEO_DMM_Badges') ? AIEO_DMM_Badges::get_family('free_shipping') : null;
if (is_array($family) && (empty($family['enabled']) || (isset($family['surfaces']['archive']) && empty($family['surfaces']['archive'])))) { return ''; }
$label = AIEO_DMM_Offer_Texts::standing_label($rule, (array) ($rule['display'] ?? array()));
if ('' === $label) { $label = self::badge_family_label(); }
self::archive_badge_style();
$set_attr = class_exists('AIEO_DMM_Offer_Sets') ? AIEO_DMM_Offer_Sets::card_attr((int) $product->get_id()) : '';
return ''
. ''
. '' . esc_html($label) . ''
. '';
}
public function enqueue_archive_badge_css() {
if (is_admin() || !function_exists('is_woocommerce')) { return; }
if (class_exists('AIEO_DMM_Badge_Renderer') && AIEO_DMM_Badge_Renderer::is_enabled()) { return; }
if (!class_exists('AIEO_DMM_Free_Shipping_Rules') || !AIEO_DMM_Free_Shipping_Rules::has_targeted()) { return; }
$post = get_post();
$wants = is_woocommerce() || ($post instanceof WP_Post && (has_block('woocommerce/product-collection', $post) || has_block('woocommerce/products', $post) || has_block('woocommerce/product-template', $post)));
if ($wants) { self::archive_badge_style(); }
}
private static function archive_badge_style() {
if (!wp_style_is('aieo-fs-badge', 'registered')) {
wp_register_style('aieo-fs-badge', false, array(), defined('AIEO_VERSION') ? AIEO_VERSION : '1');
wp_add_inline_style('aieo-fs-badge', self::archive_badge_css());
}
wp_enqueue_style('aieo-fs-badge');
}
public static function archive_badge_css() {
return '.aieo-fs-badge{display:inline-flex;align-items:center;gap:.3em;box-sizing:border-box;inline-size:max-content;max-inline-size:100%;padding:.25rem .6rem;'
. 'border-radius:var(--wp--custom--rooster--shape--badge,var(--wp--custom--rooster--shape--chip,999px));'
. 'background:var(--wp--custom--rooster--badge--background,var(--wp--preset--color--contrast,var(--wp--preset--color--fg,CanvasText)));'
. 'color:var(--wp--custom--rooster--badge--color,var(--wp--preset--color--bg,var(--wp--preset--color--base,Canvas)));font-size:var(--wp--preset--font-size--xs,.75rem);font-weight:700;line-height:1.2;white-space:nowrap}'
. '.aieo-fs-badge-icon{flex:none;inline-size:1em;block-size:1em;background:currentColor;-webkit-mask:' . AIEO_Icons::mask_url('truck') . ' center/contain no-repeat;mask:' . AIEO_Icons::mask_url('truck') . ' center/contain no-repeat}'
. '.aieo-fs-badge-text{min-inline-size:0;color:inherit;overflow:hidden;text-overflow:ellipsis}'
. '@media (forced-colors:active){.aieo-fs-badge-icon{forced-color-adjust:none;background:CanvasText}}';
}
public static function add_eligibility_row($rows, $product_id, $audience_key) {
if (!is_array($rows)) { $rows = array(); }
if ((int) $product_id !== 0) { return $rows; }
if (!class_exists('AIEO_Effective_Eligibility')) { return $rows; }
if (class_exists('AIEO_DMM_Price_Filter') && AIEO_DMM_Price_Filter::resolves()) { return $rows; }
$rows[AIEO_Effective_Eligibility::SURFACE_FREE_SHIPPING_BAR] = self::is_audience_eligible((string) $audience_key);
return $rows;
}
public static function is_audience_eligible($audience_key = 'guest') {
if (class_exists('AIEO_DMM_Settings')) {
if (!AIEO_DMM_Settings::is_module_enabled('free_shipping')) { return array('eligible' => false); }
}
$instance = self::eligibility_instance();
$s = $instance->get_settings();
$enabled = isset($s['enabled']) ? ($s['enabled'] === 'yes') : false;
$threshold = isset($s['free_shipping_threshold']) ? (float) $s['free_shipping_threshold'] : 0.0;
if (!$enabled || $threshold <= 0) { return array('eligible' => false); }
return array(
'eligible' => true,
'offer_id' => null,
'payload' => array(
'threshold' => $threshold,
'msg_initial' => isset($s['msg_initial']) ? (string) $s['msg_initial'] : '',
'msg_progress' => isset($s['msg_progress']) ? (string) $s['msg_progress'] : '',
'msg_success' => isset($s['msg_success']) ? (string) $s['msg_success'] : '',
),
);
}
private static function eligibility_instance() {
static $inst = null;
if ($inst === null) {
if (class_exists('AIEO_DMM') && method_exists('AIEO_DMM', 'instance')) {
$mod = AIEO_DMM::instance()->get_module('free_shipping');
$inst = ($mod instanceof self) ? $mod : new self();
} else {
$inst = new self();
}
}
return $inst;
}
public static function cod_fee_on() {
$stored = get_option(self::OPTION_KEY, array());
return is_array($stored) && isset($stored['cod_enabled']) && 'yes' === $stored['cod_enabled'];
}
public function get_settings($raw = false) {
$stored = get_option(self::OPTION_KEY, array());
if (!is_array($stored)) {
$stored = array();
}
$legacy = get_option('om_fs_settings', array());
if (!is_array($legacy)) {
$legacy = array();
}
$merged = array_merge(array(
'enabled' => 'yes',
'free_shipping_threshold' => isset($legacy['free_shipping_threshold']) ? (float) $legacy['free_shipping_threshold'] : 0,
'include_tax' => isset($legacy['include_tax']) ? $legacy['include_tax'] : 'no',
'msg_initial' => isset($legacy['msg_initial']) ? (string) $legacy['msg_initial'] : '',
'msg_progress' => isset($legacy['msg_progress']) ? (string) $legacy['msg_progress'] : '',
'msg_success' => isset($legacy['msg_success']) ? (string) $legacy['msg_success'] : '',
'msg_rule_product' => '',
'display_cart' => isset($legacy['display_cart']) ? $legacy['display_cart'] : 'yes',
'display_checkout' => isset($legacy['display_checkout']) ? $legacy['display_checkout'] : 'yes',
'display_mini_cart' => isset($legacy['display_mini_cart']) ? $legacy['display_mini_cart'] : 'yes',
'display_product' => isset($legacy['display_product']) ? $legacy['display_product'] : 'no',
'display_floating' => isset($legacy['display_floating']) ? $legacy['display_floating'] : 'no',
'default_country' => isset($legacy['default_country']) ? $legacy['default_country'] : '',
'default_postcode' => isset($legacy['default_postcode']) ? $legacy['default_postcode'] : '',
'bar_height' => isset($legacy['bar_height']) ? (int) $legacy['bar_height'] : 8,
'bar_border_radius' => isset($legacy['bar_border_radius']) ? (int) $legacy['bar_border_radius'] : 4,
'bar_bg_color' => isset($legacy['bar_bg_color']) ? (string) $legacy['bar_bg_color'] : '#e0e0e0',
'bar_progress_color' => isset($legacy['bar_progress_color']) ? (string) $legacy['bar_progress_color'] : '#4caf50',
'text_color' => isset($legacy['text_color']) ? (string) $legacy['text_color'] : '#333333',
'success_color' => isset($legacy['success_color']) ? (string) $legacy['success_color'] : '#2e7d32',
'amount_color' => isset($legacy['amount_color']) ? (string) $legacy['amount_color'] : '#bf4300',
'font_size' => isset($legacy['font_size']) ? (int) $legacy['font_size'] : 14,
'card_bg_color' => isset($legacy['card_bg_color']) ? (string) $legacy['card_bg_color'] : '#ffffff',
'card_padding' => isset($legacy['card_padding']) ? (int) $legacy['card_padding'] : 16,
'card_border_radius' => isset($legacy['card_border_radius']) ? (int) $legacy['card_border_radius'] : 8,
'card_border_color' => isset($legacy['card_border_color']) ? (string) $legacy['card_border_color'] : '#e0e0e0',
'notify_on_add_to_cart' => 'yes',
'notify_message' => '',
'notify_type' => 'notice',
'cod_enabled' => 'no',
'cod_fee' => 1.50,
'cod_label' => '',
'cod_taxable' => 'no',
'cod_gateway_slug' => 'cod',
'weight_exclusion_enabled' => 'no',
'max_cart_weight' => 0,
'weight_notify_message' => '',
), $stored);
return $raw ? $merged : self::fill_i18n_defaults($merged);
}
public static function i18n_hints() {
return array(
'msg_initial' => __('Free delivery on orders over {amount}', 'ai-eshop-optimizer'),
'msg_progress' => __('Only {remaining} left for free delivery', 'ai-eshop-optimizer'),
'msg_success' => __('Your order has free delivery', 'ai-eshop-optimizer'),
'msg_rule_product' => __('Free delivery with this product', 'ai-eshop-optimizer'),
'notify_message' => __('Note: this product is not eligible for free delivery. Your order will be charged for delivery, whatever its total.', 'ai-eshop-optimizer'),
'weight_notify_message' => __('Heads up: your cart is heavier than our free-shipping limit, so shipping will be charged on this order.', 'ai-eshop-optimizer'),
'cod_label' => __('Cash on delivery cost', 'ai-eshop-optimizer'),
);
}
private static function fill_i18n_defaults(array $s) {
if (!did_action('init')) { return $s; }
$i18n = array(
'msg_initial' => __('Free delivery on orders over {amount}', 'ai-eshop-optimizer'),
'msg_progress' => __('Only {remaining} left for free delivery', 'ai-eshop-optimizer'),
'msg_success' => __('Your order has free delivery', 'ai-eshop-optimizer'),
'msg_rule_product' => __('Free delivery with this product', 'ai-eshop-optimizer'),
'notify_message' => __('Note: this product is not eligible for free delivery. Your order will be charged for delivery, whatever its total.', 'ai-eshop-optimizer'),
'weight_notify_message' => __('Heads up: your cart is heavier than our free-shipping limit, so shipping will be charged on this order.', 'ai-eshop-optimizer'),
'cod_label' => __('Cash on delivery cost', 'ai-eshop-optimizer'),
);
foreach ($i18n as $k => $v) {
if (!isset($s[$k]) || '' === trim((string) $s[$k])) { $s[$k] = $v; }
}
return $s;
}
public function notify_on_add_to_cart($cart_item_key, $product_id, $quantity = 0, $variation_id = 0, $variation = array(), $cart_item_data = array()) {
if (!function_exists('wc_add_notice') || !class_exists('AIEO_DMM_Pricing_Engine')) {
return;
}
$check_id = $variation_id > 0 ? (int) $variation_id : (int) $product_id;
if ($check_id <= 0) { return; }
if (AIEO_DMM_Pricing_Engine::instance()->is_excluded_from_free_shipping($check_id)) {
$settings = $this->get_settings();
$msg = isset($settings['notify_message']) && $settings['notify_message'] !== ''
? (string) $settings['notify_message']
: __('Note: this product is not eligible for free delivery.', 'ai-eshop-optimizer');
$type = (isset($settings['notify_type']) && $settings['notify_type'] === 'error') ? 'error' : 'notice';
wc_add_notice($msg, $type);
}
}
public function render_product_page_notice() {
if (!function_exists('wc_get_product') || !class_exists('AIEO_DMM_Pricing_Engine')) {
return;
}
global $product;
if (!$product || !is_a($product, 'WC_Product')) {
return;
}
$pid = (int) $product->get_id();
if (!AIEO_DMM_Pricing_Engine::instance()->is_excluded_from_free_shipping($pid)) {
return;
}
$settings = $this->get_settings();
$msg = isset($settings['notify_message']) && $settings['notify_message'] !== ''
? (string) $settings['notify_message']
: __('Note: this product is not eligible for free delivery.', 'ai-eshop-optimizer');
echo self::product_notice_html($msg);
}
public static function product_notice_html($msg) {
if ('' === trim((string) $msg) || !function_exists('wc_print_notice')) {
return '';
}
return '