Settings > Products > Warranty Desk. */ final class Settings { public const SECTION = 'warranty_desk'; private const FIELD_TYPE = 'abcreate_wd_media'; public function __construct(private readonly string $pluginFile) { } public function register(): void { add_filter('woocommerce_get_sections_products', [$this, 'addSection']); add_filter('woocommerce_get_settings_products', [$this, 'addFields'], 20, 2); add_action('woocommerce_admin_field_' . self::FIELD_TYPE, [$this, 'renderMediaField']); add_filter('woocommerce_admin_settings_sanitize_option_' . Options::NOTICE_ATTACHMENT, static fn ($value) => absint($value)); add_filter('plugin_action_links_' . plugin_basename($this->pluginFile), [$this, 'actionLinks']); } /** * @param array $sections * @return array */ public function addSection($sections) { $sections = is_array($sections) ? $sections : []; $sections[self::SECTION] = __('Warranty Desk', 'abcreate-warranty-desk'); return $sections; } /** * @param array> $settings * @return array> */ public function addFields($settings, $currentSection) { if (self::SECTION !== $currentSection) { return $settings; } return [ [ 'title' => __('Dates and targets', 'abcreate-warranty-desk'), 'type' => 'title', 'desc' => __('Guarantee dates start from delivery. Until a delivery is confirmed by hand, it is estimated from the day the order was completed.', 'abcreate-warranty-desk'), 'id' => 'abcreate_wd_dates', ], [ 'title' => __('Transit days', 'abcreate-warranty-desk'), 'desc' => __('Days added to the completion date to estimate the delivery.', 'abcreate-warranty-desk'), 'id' => Options::TRANSIT_DAYS, 'type' => 'number', 'default' => '0', 'custom_attributes' => ['min' => '0', 'max' => '60', 'step' => '1'], ], [ 'title' => __('Target days for a remedy', 'abcreate-warranty-desk'), 'desc' => __('The law asks for a reasonable time without giving a number: claims open longer than this are highlighted.', 'abcreate-warranty-desk'), 'id' => Options::TARGET_DAYS, 'type' => 'number', 'default' => '30', 'custom_attributes' => ['min' => '1', 'max' => '365', 'step' => '1'], ], ['type' => 'sectionend', 'id' => 'abcreate_wd_dates'], [ 'title' => __('Informativa email', 'abcreate-warranty-desk'), 'type' => 'title', 'desc' => __('Sent before the remedy (art. 135-bis c. 2-bis of the Consumer Code). Leave empty to use the built-in text. Placeholders: {customer_name}, {order_number}, {product_name}, {reported_on}, {shop_name}, {extension_paragraph} (the sentence on the 12-month extension, or that it was already used).', 'abcreate-warranty-desk'), 'id' => 'abcreate_wd_informativa', ], [ 'title' => __('Subject', 'abcreate-warranty-desk'), 'id' => Options::INFORMATIVA_SUBJECT, 'type' => 'text', 'placeholder' => InformativaMailer::defaultSubject(), 'css' => 'width: 100%; max-width: 600px;', ], [ 'title' => __('Text', 'abcreate-warranty-desk'), 'id' => Options::INFORMATIVA_BODY, 'type' => 'textarea', 'placeholder' => InformativaMailer::defaultBody(), 'css' => 'width: 100%; max-width: 600px; height: 280px;', ], ['type' => 'sectionend', 'id' => 'abcreate_wd_informativa'], [ 'title' => __('Harmonised EU notice', 'abcreate-warranty-desk'), 'type' => 'title', 'desc' => __('From 27 September 2026 shops must show the EU harmonised notice on the legal guarantee (Regulation (EU) 2025/1960). Upload the official file in your language from the European Commission and choose it here: it is shown in the site footer and at checkout. You can also place it with the [warranty_desk_notice] shortcode.', 'abcreate-warranty-desk'), 'id' => 'abcreate_wd_notice', ], [ 'title' => __('Notice file', 'abcreate-warranty-desk'), 'id' => Options::NOTICE_ATTACHMENT, 'type' => self::FIELD_TYPE, ], [ 'title' => __('Text alternative', 'abcreate-warranty-desk'), 'desc' => __('Read by screen readers instead of the image.', 'abcreate-warranty-desk'), 'id' => Options::NOTICE_ALT, 'type' => 'text', 'default' => '', 'css' => 'width: 100%; max-width: 600px;', ], ['type' => 'sectionend', 'id' => 'abcreate_wd_notice'], [ 'title' => __('Data', 'abcreate-warranty-desk'), 'type' => 'title', 'desc' => sprintf( /* translators: 1: link to the claims CSV, 2: link to the history CSV */ __('Export before deleting the plugin: %1$s, %2$s.', 'abcreate-warranty-desk'), '' . esc_html__('claims (CSV)', 'abcreate-warranty-desk') . '', '' . esc_html__('full history (CSV)', 'abcreate-warranty-desk') . '', ), 'id' => 'abcreate_wd_data', ], [ 'title' => __('Data when deleting the plugin', 'abcreate-warranty-desk'), 'desc' => __('Delete all Warranty Desk data (units, claims and history) when the plugin is deleted. Leave it off to keep the data for a later reinstall.', 'abcreate-warranty-desk'), 'id' => Options::DELETE_ON_UNINSTALL, 'type' => 'checkbox', 'default' => 'no', ], ['type' => 'sectionend', 'id' => 'abcreate_wd_data'], ]; } /** @param array $field */ public function renderMediaField($field): void { wp_enqueue_media(); $id = Options::noticeAttachmentId(); $preview = $id > 0 ? wp_get_attachment_image($id, 'medium', true) : ''; $name = $id > 0 ? basename((string) get_attached_file($id)) : ''; ?>

0 && !wp_attachment_is_image($id)) : ?>

").attr("src",img).css("max-width","300px")).append("
").append($("").text(a.filename));remove.show();});}frame.open();});' . 'remove.on("click",function(e){e.preventDefault();input.val("0");box.empty();remove.hide();});})(jQuery);', esc_js(Options::NOTICE_ATTACHMENT), wp_json_encode(__('Harmonised EU notice', 'abcreate-warranty-desk')), ); // The settings page prints jQuery in the head: run once the page is complete. add_action('admin_print_footer_scripts', static function () use ($script): void { wp_print_inline_script_tag($script); }, 99); } /** * @param array $links * @return array */ public function actionLinks($links) { $links = is_array($links) ? $links : []; array_unshift( $links, '' . esc_html__('Claims', 'abcreate-warranty-desk') . '', '' . esc_html__('Settings', 'abcreate-warranty-desk') . '', ); return $links; } }