=== Arik Product Fields — WooCommerce Custom Fields, Buy Now, Enquiry Form & Coupon ===
Contributors: wcblogs87
Tags: woocommerce custom fields, buy now button, product enquiry form, product addons, woocommerce coupon
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.1.0
WC requires at least: 6.0
WC tested up to: 10.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Custom product fields with a drag-and-drop builder, Buy Now button, Enquiry Form, Coupon Box, and 20 field types for WooCommerce.

== Description ==

**Arik Product Fields** is a complete toolkit for WooCommerce product pages. Build custom product fields with a drag-and-drop visual builder, add a Buy Now button that skips the cart, accept enquiries through a polished modal form, show coupon codes directly on the product page, and clean up the single product layout all without writing a single line of code.

Designed for store owners who want more conversions, better data collection, and a faster checkout experience.

= Why store owners pick Arik Product Fields =

* **One plugin, five jobs.** Custom fields, Buy Now, Enquiry form, coupon box, and checkout tweaks no need to stack five separate plugins.
* **Beautiful frontend.** Theme-aware styling that inherits your color tokens and looks native in Storefront, Astra, Flatsome, OceanWP, and Blocksy.
* **HPOS compatible.** Declared compatibility with WooCommerce Custom Order Tables and the new cart/checkout blocks.
* **Built for developers.** 11+ public actions and filters, a Support & Docs page with copy-paste examples, and translation-ready strings.
* **No bloat.** Assets load only on the screens that need them. Admin styles never leak into unrelated pages.

= 20 field types =

**Input fields** (collect data from customers):

* Text
* Textarea
* Number
* E-mail
* URL
* Checkbox (multi-option)
* Select / Dropdown
* Radio
* Radio with images (WP Media Library picker)
* Radio with colors (WordPress color picker)
* Time
* Color
* Date

**Display / Content fields** (admin enters content, frontend shows it):

* Heading
* Paragraph
* HTML
* Image (Media Library picker + URL fallback)
* Product Video (YouTube, Vimeo, or direct MP4/WebM/OGG)

**Dynamic fields** (populated from the current product):

* Categories rendered as checkboxes built from the product's own categories
* Tags rendered as checkboxes built from the product's own tags

= Feature highlights =

* **Drag-and-drop field builder** powered by jQuery UI Sortable. Click any field type in the palette to add it. Drag rows by the handle to reorder. Inline editor with per-type controls.
* **Per-product field assignment** through a dedicated Product Data tab. Pick which fields appear on which products. Leave it empty to use global-scope fields.
* **Buy Now button** that skips the cart and lands the customer on checkout (or cart your choice).
* **Enquiry form** in an accessible modal. Sends email to admin, stores submissions as a custom post type, and recommends Contact Form 7 as a more robust alternative.
* **Coupon code box** on the single product page with four position options.
* **Checkout modifications** add an optional Order Reference field, make phone optional, soften default placeholders.
* **Hide SKU and Categories/Tags** on single product pages globally or per-product.
* **Tri-state per-product overrides** for Buy Now and Enquiry: "Use global setting", "Show", or "Hide".
* **Configurable field position** render fields before/after price, before/after Add to Cart, or before/after Buy Now.
* **Design tab** style the frontend fields without writing CSS: container background, border, radius, padding and spacing, one- or two-column layout, label typography, input colours and sizing, radio/checkbox pill shape and selected state, button colours, plus an Additional CSS box. Four presets and a live preview that renders with your storefront's own stylesheet. Ships switched off, so upgrading never changes how your product pages look.
* **Support & Docs admin page** with the full developer hook reference and code examples.
* **Translation-ready** with `wp_set_script_translations()` for the builder UI.

= Security =

* WordPress nonces on every form and AJAX endpoint.
* Capability checks on every admin action (`manage_woocommerce`, `edit_product`).
* Honeypot field plus per-IP rate limiting on the enquiry form.
* Type-aware sanitization with a strict allowlist per field type.
* Output escaped per WordPress.org guidelines (`esc_html`, `esc_attr`, `esc_url`, `wp_kses_post`).

= Developer-friendly =

The plugin exposes 11+ public hooks for theme and plugin developers:

* Filters: `arikapf_render_field_definitions`, `arikapf_cart_item_field_values`, `arikapf_buy_now_button_label`, `arikapf_enquiry_button_label`, `arikapf_buy_now_enabled_for_product`, `arikapf_enquiry_enabled_for_product`, `arikapf_hide_sku`, `arikapf_hide_categories`, `arikapf_fields_render_hook`, `arikapf_support_marketing_links`, `arikapf_checkout_fields`.
* Actions: `arikapf_before_render_fields`, `arikapf_after_render_fields`, `arikapf_before_buy_now_button`, `arikapf_after_buy_now_button`, `arikapf_before_enquiry_button`, `arikapf_after_enquiry_button`, `arikapf_enquiry_submitted`, `arikapf_after_save_product_meta`, `arikapf_after_cart_item_meta_added`.

Each hook is documented inside the plugin under **Arik Fields → Support & Docs**, with copy-paste code examples.

= Compatible with =

* WordPress 6.0+
* WooCommerce 6.0+ (tested through 9.4)
* PHP 7.4+
* HPOS (Custom Order Tables)
* WooCommerce Cart & Checkout Blocks
* Contact Form 7 (for the enquiry form)
* Storefront, Astra, Flatsome, OceanWP, Blocksy, and any properly built block theme


== Additional Information ==

= Support & Connect =
* **Email Support:** helpwcblog@gmail.com
* **Website:** **[https://gernx.com/](https://gernx.com/)** 
* **Support Forum:** [WordPress.org Support](https://wordpress.org/support/plugin/arik-product-fields/)
* **LinkedIn:** [Tanmoy Biswas](https://www.linkedin.com/in/is-tanmoy/)


== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` or install through the **Plugins** menu in WordPress.
2. Activate **Arik Product Fields** through the **Plugins** screen.
3. Go to **Arik Fields → Field Builder** to create your custom fields.
4. Go to **Arik Fields → Settings** to configure Buy Now, Enquiry, Coupon, and field position.
5. Edit any product and open the **Arik Fields** tab to assign which fields appear on that product.

== Frequently Asked Questions ==

= Does this work with the WooCommerce Block Checkout? =

Yes. HPOS and `cart_checkout_blocks` compatibility is declared in the plugin header.

= Can I use Contact Form 7 instead of the built-in enquiry form? =

Yes. Enable it under **Arik Fields → Settings → Enquiry Form**, then pick the CF7 form you want to display in the modal.

= Where do submitted enquiries go? =

By default, enquiries are emailed to the address in **Settings → Enquiry Form → Recipient Email** AND stored as a custom post type at **Arik Fields → Enquiries**. Either destination can be disabled.

= Can I override Buy Now or Enquiry on a single product? =

Yes. Each product has its own tri-state dropdown in the **Arik Fields** tab: *Use global setting*, *Show on this product*, or *Hide on this product*.

= My theme has different button styles. Will the plugin's buttons look out of place? =

The frontend stylesheet inherits theme color tokens like `--wp--preset--color--primary` where available. Buttons and form controls pick up your theme's accent color automatically in modern themes.

= Does the plugin slow down my site? =

No. CSS and JavaScript only load on single product pages, the cart, and the checkout. Admin assets only load on the plugin's own screens. The fields table is indexed and cached via the WordPress object cache.

= Can I extend the plugin from a child theme or custom plugin? =

Yes. See the full hook reference at **Arik Fields → Support & Docs**, or check the Description section above. There are 11+ documented hooks plus a `arikapf_fields_render_hook` filter that lets you move the field render position to any WooCommerce action you want.

= Is the plugin translation-ready? =

Yes. Text domain is `arik-product-fields`, all translatable strings use proper translator comments, and `wp_set_script_translations()` is wired up for the builder UI.

= What happens to my data if I delete the plugin? =

Nothing, by default. The uninstaller only runs if you opt in via **Settings → Advanced → Remove all data on uninstall**. Otherwise your fields, settings, and enquiries remain in the database.

== Changelog ==

= 1.1.0 — Buy Now Fix & Design Tab =

**Fixed**

* **Buy Now did nothing / never reached checkout on simple products.** A browser only submits the name and value of the button that was actually clicked, and WooCommerce's own Add to Cart control *is* that button (`name="add-to-cart"`). Clicking Buy Now therefore posted the form without `add-to-cart`, so `WC_Form_Handler` bailed out, nothing was added, and the redirect filter never ran — the page simply reloaded. The button now carries the product ID and the parameter is restored both client-side and server-side (`wp_loaded`, priority 15), so Buy Now works with JavaScript on or off.
* Required custom fields did not actually block Add to Cart. `woocommerce_add_cart_item_data` cannot stop an item being added — validation moved to `woocommerce_add_to_cart_validation`, the hook WooCommerce honours.
* Fields placed at **Before Price** / **After Price** collected nothing. Those positions render outside `form.cart`, and controls outside a form are never posted. Out-of-form values are now mirrored into the cart form on submit, so all six positions behave identically.
* Text values lost one level of backslashes (`C:\path` became `C:path`) — `wp_unslash()` was applied twice on the way into the sanitizer.
* Every Add to Cart created a brand-new cart line even when the field values were identical, because the line's uniqueness hash was seeded with `microtime()`. Identical selections now merge and increase quantity as expected.
* Saving a field whose key already existed failed against the `UNIQUE` index and surfaced only as "Database error while saving field." Duplicate keys are now suffixed automatically.
* Applying a coupon from the product page wiped every queued WooCommerce notice, not just its own. Unrelated notices are now preserved.
* Buy Now no longer renders on external and grouped products, which have no single add-to-cart form to submit.
* **Buy Now appeared greyed out / disabled on the product page.** On a variable product the button is rendered inside `.woocommerce-variation-add-to-cart`, and both WooCommerce core and most themes dim every `.button` in that container while no variation is picked — the Buy Now button inherited that styling by accident and never lost it. Its enabled/disabled state is now driven explicitly and kept in step with the variation picker. The in-flight "busy" state also moved from `click` to `submit`, so a cancelled submission (an empty required field, another add-on's validator, a theme handler) no longer leaves the button permanently dimmed and unclickable, and returning via the browser's back button resets it.
* The `arikapf_daily_cleanup` cron event was scheduled on activation but had no listener; it now prunes expired enquiry rate-limit transients. Deactivation clears every occurrence instead of just the next one.
* The enquiry modal left its own `$product` in the global scope after running in `wp_footer`; the previous value is restored.
* Hex colour sanitizing rewritten — `#ABC`, `#AABBCC` and 8-digit values normalise consistently, invalid input is discarded.
* `_arikapf_hide_sku` and `_arikapf_hide_categories` post meta are now removed by the opt-in uninstaller.

**New**

* **Design tab** (Arik Fields → Settings → Design). Style the frontend fields without touching CSS: container background, border, corner radius, padding and spacing; one- or two-column layout; label colour, size and weight; input colours, radius, padding and font size; radio and checkbox pill radius and selected state; button colours and radius; the enquiry trigger's outline; plus an Additional CSS box.
* Four starting points — Classic, Soft card, Minimal, Bold — and a **live preview** that renders with your storefront's actual stylesheet as you drag the sliders.
* The Design tab ships **switched off**. Until you enable it, no extra CSS is printed and the frontend is byte-identical to 1.0.8.
* New filters: `arikapf_design_settings`, `arikapf_design_css_vars`, `arikapf_design_inline_css`, `arikapf_sanitize_design_settings`, `arikapf_settings_tabs`, `arikapf_buy_now_redirect_url`, `arikapf_buy_now_unsupported_types`, `arikapf_add_to_cart_validation`.

**Improved**

* The whole frontend stylesheet is now driven by CSS custom properties, so a child theme can restyle any part of the plugin with a single `:root` override.
* Frontend scripts load only when the feature that needs them is actually enabled for the product being viewed.
* Settings screen split into General and Design tabs.
* Builder UI strings that were hard-coded English (Label, Field Key, Type, Options, Cancel, Save Field, Edit, Delete, error messages) are translatable.
* Ordered field values are also stored as raw machine values in `_arikapf_fields` order item meta for integrations and re-orders.
* No database migration. Existing fields, settings and enquiries are untouched.

= 1.0.8 — Maintenance & Compatibility =

Maintenance and compatibility release. No functions, features, styles, or CSS were changed; this release only refreshes the version number and the compatibility headers so the plugin reports as tested against current WordPress and WooCommerce.

* Compatibility: Confirmed against WordPress 7.0 — `Tested up to` raised from 6.7 to 7.0 (resolves the "not tested with the latest 3 major releases of WordPress" notice).
* Compatibility: Tested with WooCommerce 10.9 — `WC tested up to` raised from 9.4 to 10.9. Continues to declare HPOS (High-Performance Order Storage) compatibility and uses standard WooCommerce APIs.
* Housekeeping: Plugin header `Version` and the `ARIKAPF_VERSION` constant bumped to 1.0.8; `Stable tag` updated to 1.0.8.

= 1.0.7 — Field Type Expansion =

**New**

* Redesigned the field type set. The plugin now ships **20 field types**: Text, Textarea, Number, E-mail, URL, Checkbox, Select, Radio, Radio with images, Radio with colors, Time, Color, Heading, Paragraph, Image, HTML, Product Video, Date, Categories (dynamic), Tags (dynamic).
* Builder palette now groups field types into three sections: **Input Fields**, **Display / Content**, **Dynamic**.
* Per-option **Image picker** for "Radio with images" — uses the WP Media Library with a URL fallback input.
* Per-option **Color picker** for "Radio with colors" — uses the core `wp-color-picker`.
* Dedicated content editor for **Heading**, **Paragraph**, **HTML**, **Image**, and **Video** field types.
* **Categories** and **Tags** field types render as dynamic checkbox groups built from the current product's assigned terms.
* **Product Video** embed supports YouTube, Vimeo, and direct MP4/WebM/OGG files.
* Cart and order detail screens now translate option slugs to their human-readable labels, and taxonomy slugs to term names.
* CF7 recommendation banner inside the enquiry modal — admin-only, capability-gated so customers never see it.

**Fixed**

* New checkbox / dropdown / multi-select / radio fields failing to save options on first creation. The builder now writes the full field JSON to a `data-field-data` attribute on each list row, so editing existing option-type fields after a page reload hydrates correctly.
* Silent save failures — the status bar now shows a clear error message and focuses the offending field.
* Customer-facing error messages no longer mention "Contact Form 7" or other plugin recommendations.
* Multi-select listbox cramped rendering — now uses dynamic `size` attribute and per-option padding so options read consistently across themes.
* Dropdown vertical alignment — the selected value was clipped on some themes due to insufficient padding.
* Checkbox field renders as a proper multi-option group instead of a single boolean toggle.
* `Notice: Function _load_textdomain_just_in_time was called incorrectly` on WordPress 6.7+ — translation calls in default option arrays moved out of the bootstrap phase.
* Builder UI required both `value` and `label` to be filled; now mirrors the missing field automatically.

**Database**

* DB schema bumped to **1.1.0**. New `field_content` column added for display-only types.
* **DESTRUCTIVE migration**: existing custom fields are wiped on upgrade. The previous type set is not forward-compatible with the new shape registry. Recreate your fields in the builder.

**Removed**

* `Multi-select` and `File Upload` field types from the previous set — replaced by the redesigned 20-type catalog. (Multi-select behavior is now covered by the new multi-option **Checkbox** field; file uploads are planned for a future release.)

= 1.0.6 — Developer Hooks & Display Controls =

**New**

* Configurable position for custom fields (before/after price, ATC button, or Buy Now button).
* Option to hide SKU and Categories/Tags on single product pages — globally and per-product.
* Tri-state per-product override for Buy Now and Enquiry Form: *Default / Show / Hide*.
* **Support & Docs** admin page with the full hook reference and developer code examples.
* Marketing card with Fiverr, LinkedIn, and donate links.
* 11+ public actions and filters for theme and plugin developers.

**Fixed**

* Enquiry button visibility logic — per-product override now correctly resolves against the global setting.
* Admin CSS scoped to plugin screens only — no longer leaks onto unrelated admin pages.
* Tightened admin enqueue — assets load only on the plugin's own screens and the product edit screen.

= 1.0.5 — Critical Activation Fix =

**Fixed**

* Fatal error on activation/upgrade caused by re-running the activator on `plugins_loaded` (before `$wp_rewrite` was initialised).

**Refactored**

* DB upgrade path moved to `admin_init`.
* CPT registration consolidated to the main class on the `init` action.

= 1.0.4 — Initial Feature Release =

**New**

* Complete drag-and-drop field builder powered by jQuery UI Sortable.
* Per-product field assignment via the Product Data tab.
* Enquiry form modal with database storage, email delivery, and Contact Form 7 fallback.
* Coupon code box with four position options.
* HPOS and cart/checkout blocks compatibility declared.
* Clean uninstaller with opt-in data removal.
* Type-aware sanitization and validation pipeline.

== Upgrade Notice ==

= 1.1.0 =
Fixes the Buy Now button, which did not reach checkout on simple products, and makes required fields actually block Add to Cart. Adds a Design tab for styling the frontend fields without CSS. No database migration — your fields and settings are preserved.

= 1.0.8 =
Maintenance and compatibility release. Refreshes compatibility for WordPress 7.0 and WooCommerce 10.9 and clears the "not tested with the latest 3 major releases" notice. No functions, features, styles, or CSS were changed.

= 1.0.7 =
DESTRUCTIVE: existing custom fields will be wiped on upgrade (schema redesigned). The new 20-type catalog adds image, color, video, date, time, and dynamic taxonomy field types. Recreate your fields in the builder after upgrading.

= 1.0.6 =
Major: developer hooks, configurable field position, SKU/categories hide options, Support & Docs page.

= 1.0.5 =
Critical fix for a fatal error on activation. Update immediately.

= 1.0.4 =
Major release: drag-and-drop builder, HPOS support, enquiry custom post type.

== Screenshots ==

1. screenshot-1.png
2. screenshot-2.png
3. screenshot-3.png
4. screenshot-4.png
5. screenshot-5.png
