$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 ? $text : __('On', 'ai-eshop-optimizer'), 'label_hidden' => '' === $text));
};
$aieo_fs_card = static function ($anchor, $icon, $title, $description, $fields, $after = '') {
$form_id = 'aieo-card-' . $anchor . '-form';
list($open, $close) = AIEO_DMM_UI::card(array(
'anchor' => $anchor,
'icon' => $icon,
'title' => $title,
'description' => $description,
'footer' => \Rooster\Admin\States::save_button($form_id, array('label' => __('Save settings', 'ai-eshop-optimizer'))),
'col' => 1,
));
echo $open;
echo AIEO_DMM_UI::card_form('aieo_dmm_free_shipping_save', 'free_shipping_eligibility', $form_id, '
' . $fields . '
');
echo $after;
echo $close;
};
$aieo_fs_fields = $aieo_fs_row('enabled', __('Enabled', 'ai-eshop-optimizer'), $aieo_fs_switch('enabled', $settings['enabled'] === 'yes'));
$aieo_fs_offers = class_exists('AIEO_DMM_Free_Shipping_Bar') && AIEO_DMM_Free_Shipping_Bar::reads_offers();
$aieo_fs_fields .= $aieo_fs_row('free_shipping_threshold', __('Threshold', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('free_shipping_threshold', (string) $settings['free_shipping_threshold'], array('id' => $aieo_fs_id('free_shipping_threshold'), 'type' => 'number', 'step' => 'any', 'min' => '0', 'short' => true, 'unit' => $aieo_fs_currency) + ($aieo_fs_offers ? array('readonly' => true) : array())), $aieo_fs_offers ? __('With the one offers store, each free-shipping offer sets its own threshold; this field is kept for a return to the old store.', 'ai-eshop-optimizer') : '');
$aieo_fs_fields .= $aieo_fs_row('include_tax', __('Include tax', 'ai-eshop-optimizer'), $aieo_fs_switch('include_tax', $settings['include_tax'] === 'yes'), $aieo_fs_offers ? __('Not used: the free-shipping bars count the cart as your shop displays prices, with tax when it displays them with tax.', 'ai-eshop-optimizer') : '');
$aieo_fs_fields .= $aieo_fs_row('default_country', __('Default country (ISO)', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('default_country', (string) $settings['default_country'], array('id' => $aieo_fs_id('default_country'), 'short' => true)));
$aieo_fs_fields .= $aieo_fs_row('default_postcode', __('Default postcode', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('default_postcode', (string) $settings['default_postcode'], array('id' => $aieo_fs_id('default_postcode'), 'short' => true)));
$aieo_fs_moved = sprintf(
esc_html__('Display settings — messages, where the bar appears, the early-signal notice, and the visual styling — moved to %s.', 'ai-eshop-optimizer'),
'' . esc_html__('Visual Display → Free Shipping Display', 'ai-eshop-optimizer') . ''
);
$aieo_fs_moved_html = \Rooster\Admin\Guidance::text('', 'guidance', array('html' => $aieo_fs_moved));
$aieo_fs_card(
'free-shipping-settings',
'settings',
__('Free shipping settings', 'ai-eshop-optimizer'),
__('The frontend progress bar lives in om-free-shipping. These settings are kept in sync so the existing plugin keeps working. The exclusion list below is enforced by DMM directly (removes free shipping rates when any excluded product is in the cart).', 'ai-eshop-optimizer'),
$aieo_fs_fields,
$aieo_fs_moved_html
);
$aieo_fs_fields = $aieo_fs_row('weight_exclusion_enabled', __('Enable weight-based exclusion', 'ai-eshop-optimizer'), $aieo_fs_switch('weight_exclusion_enabled', (isset($settings['weight_exclusion_enabled']) ? $settings['weight_exclusion_enabled'] : 'no') === 'yes', __('Remove free shipping when total cart weight is over the threshold.', 'ai-eshop-optimizer')));
$aieo_fs_fields .= $aieo_fs_row(
'max_cart_weight',
sprintf(__('Max cart weight (%s)', 'ai-eshop-optimizer'), $weight_unit),
\Rooster\Admin\Ui::input('max_cart_weight', (string) (isset($settings['max_cart_weight']) ? $settings['max_cart_weight'] : 0), array('id' => $aieo_fs_id('max_cart_weight'), 'type' => 'number', 'step' => 'any', 'min' => '0', 'xs' => true))
);
$aieo_fs_fields .= $aieo_fs_row(
'weight_notify_message',
__('Weight-cap notice text', 'ai-eshop-optimizer'),
\Rooster\Admin\Ui::textarea('weight_notify_message', isset($settings['weight_notify_message']) ? (string) $settings['weight_notify_message'] : '', array('id' => $aieo_fs_id('weight_notify_message'), 'rows' => 2)),
__('Shown on the cart and checkout when the total weight has stripped free shipping. Leave blank to suppress the message (the rate is still removed).', 'ai-eshop-optimizer')
);
$aieo_fs_card(
'free-shipping-cart-weight-cap',
'scale',
__('Cart weight cap', 'ai-eshop-optimizer'),
sprintf(
__('Strip free shipping when the total cart weight exceeds the threshold below. Uses WooCommerce\'s configured store weight unit (%s). Set the threshold to 0 to disable this rule.', 'ai-eshop-optimizer'),
$weight_unit
),
$aieo_fs_fields
);
$aieo_fs_nf_form = 'aieo-dmm-fs-never-free-form';
$aieo_fs_nf_export = 'aieo-dmm-fs-never-free-export';
$aieo_fs_nf_title = __('Products never eligible for free shipping', 'ai-eshop-optimizer');
list($aieo_fs_nf_open, $aieo_fs_nf_close) = AIEO_DMM_UI::card(array(
'anchor' => 'free-shipping-never-free',
'icon' => 'ban',
'title' => __('Products never eligible for free shipping', 'ai-eshop-optimizer'),
'description' => __('A cart that holds one of these products gets no free shipping, whatever an offer or a shipping method says: WooCommerce’s free shipping is taken away, a shipping rate’s free row gives way to its paid one, and Box Now keeps its cost. A shipping rate with no paid price at all stays free. The no-free-shipping gate, set with the Customer Discounts, can soften this or switch it off.', 'ai-eshop-optimizer'),
'footer' => \Rooster\Admin\Ui::button(__('Add to the list', 'ai-eshop-optimizer'), array('type' => 'submit', 'variant' => 'primary', 'attrs' => array('form' => $aieo_fs_nf_form, 'data-action' => 'aieo_dmm_free_shipping_add_exclusions')))
. \Rooster\Admin\Ui::button(__('Export CSV', 'ai-eshop-optimizer'), array('type' => 'submit', 'icon' => 'download', 'attrs' => array('form' => $aieo_fs_nf_export, 'data-action' => 'aieo_dmm_free_shipping_export_exclusions'))),
'col' => 1,
));
echo $aieo_fs_nf_open;
echo '';
$aieo_fs_nf_fields = \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-fs-nf-ids',
'label' => __('Product IDs', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::textarea('product_ids', '', array('id' => 'aieo-fs-nf-ids', 'rows' => 2)),
'help' => __('Separated by commas, spaces or new lines. A variation’s ID adds its product.', 'ai-eshop-optimizer'),
));
$aieo_fs_nf_fields .= \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-fs-nf-csv',
'label' => __('Or a CSV file', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::file('csv_file', array('id' => 'aieo-fs-nf-csv', 'accept' => '.csv,text/csv')),
'help' => __('Every number in the file is read as a product ID.', 'ai-eshop-optimizer'),
));
$aieo_fs_nf_fields .= \Rooster\Admin\Ui::field_row(array(
'id' => 'aieo-fs-nf-mode',
'label' => __('What to do with them', 'ai-eshop-optimizer'),
'control' => \Rooster\Admin\Ui::select('mode', array(
'append' => __('Add them to the list', 'ai-eshop-optimizer'),
'replace' => __('Replace the whole list with them', 'ai-eshop-optimizer'),
), 'append', array('id' => 'aieo-fs-nf-mode')),
));
$aieo_fs_nf_ask = 'aieo-fs-never-free-replace';
echo '';
echo \Rooster\Admin\States::confirm($aieo_fs_nf_ask, 'replace', __('Replace the whole list?', 'ai-eshop-optimizer'), '', array('confirm' => __('Replace the list', 'ai-eshop-optimizer'), 'say' => true));
if (empty($exclusions)) {
echo \Rooster\Admin\States::state('first-use', array('title' => __('No product is on the list.', 'ai-eshop-optimizer'), 'compact' => true));
} else {
$aieo_fs_nf_rows = array();
foreach ((array) $exclusions as $aieo_fs_nf_row) {
$aieo_fs_nf_id = (int) $aieo_fs_nf_row['product_id'];
$aieo_fs_nf_name = '' !== trim((string) ($aieo_fs_nf_row['title'] ?? '')) ? (string) $aieo_fs_nf_row['title'] : '#' . $aieo_fs_nf_id;
$aieo_fs_nf_edit = '' !== trim((string) ($aieo_fs_nf_row['title'] ?? '')) ? (string) get_edit_post_link($aieo_fs_nf_id, 'raw') : '';
$aieo_fs_nf_rows[] = array(
'_id' => $aieo_fs_nf_id,
'_name' => $aieo_fs_nf_name,
'_attrs' => array('data-product-id' => $aieo_fs_nf_id),
'product' => '' !== $aieo_fs_nf_edit ? array('html' => '' . esc_html($aieo_fs_nf_name) . '') : $aieo_fs_nf_name,
'sku' => (string) ($aieo_fs_nf_row['sku'] ?? ''),
'actions' => \Rooster\Admin\Ui::button(
__('Remove', 'ai-eshop-optimizer'),
array(
'size' => 'sm',
'variant' => 'ghost',
'class' => 'aieo-dmm-remove-exclusion',
'attrs' => array('aria-label' => sprintf(__('Remove %s from the list', 'ai-eshop-optimizer'), $aieo_fs_nf_name)),
)
),
);
}
echo \Rooster\Admin\Ui::table(
array(
array('key' => 'product', 'label' => __('Product', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'sku', 'label' => __('SKU', 'ai-eshop-optimizer'), 'type' => 'text'),
array('key' => 'actions', 'label' => __('Actions', 'ai-eshop-optimizer'), 'type' => 'html'),
),
$aieo_fs_nf_rows,
array('id' => 'aieo-fs-never-free', 'caption' => esc_html($aieo_fs_nf_title))
);
if ((int) $exclusion_count > (int) $per_page) {
echo \Rooster\Admin\Ui::pager(
(int) $current_page,
(int) ceil((int) $exclusion_count / max(1, (int) $per_page)),
add_query_arg(array('page' => AIEO_DMM::MENU_SLUG, 'dmm_tab' => 'free_shipping'), admin_url('admin.php')) . '#aieo-card-free-shipping-never-free',
array('total' => (int) $exclusion_count, 'per_page' => (int) $per_page, 'label' => $aieo_fs_nf_title)
);
}
}
echo $aieo_fs_nf_close;