'; woocommerce_wp_text_input([ 'id' => Options::PRODUCT_MONTHS_META, 'label' => __('Legal guarantee (months)', 'abcreate-warranty-desk'), 'placeholder' => (string) LegalRules::GUARANTEE_MONTHS, 'desc_tip' => true, 'description' => __('Leave empty for 24 months. Only for used goods, and only if agreed with the buyer, it can be reduced down to 12 months.', 'abcreate-warranty-desk'), 'type' => 'number', 'custom_attributes' => ['min' => (string) LegalRules::MIN_USED_GOODS_MONTHS, 'max' => (string) LegalRules::GUARANTEE_MONTHS, 'step' => '1'], ]); wp_nonce_field('abcreate_wd_product_months', '_abcreate_wd_months_nonce'); echo ''; } /** @param \WC_Product $product */ public function save($product): void { if (!$product instanceof \WC_Product || !isset($_POST['_abcreate_wd_months_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_abcreate_wd_months_nonce'])), 'abcreate_wd_product_months')) { return; } $raw = isset($_POST[Options::PRODUCT_MONTHS_META]) ? sanitize_text_field(wp_unslash($_POST[Options::PRODUCT_MONTHS_META])) : ''; if ('' === $raw) { $product->delete_meta_data(Options::PRODUCT_MONTHS_META); return; } $months = max(LegalRules::MIN_USED_GOODS_MONTHS, min(LegalRules::GUARANTEE_MONTHS, (int) $raw)); $product->update_meta_data(Options::PRODUCT_MONTHS_META, $months); } }