Checkout Fields for Gifts

User
At Checkout page we need to add fields to know where the flowers are to be sent (as they are likely to be gifted)? Both Eircode and phone number to be made mandatory
also include it in order email
Assistant
To achieve this in WooCommerce, you need to:

1. **Add custom fields to the checkout page.**
2. **Make Eircode and phone number mandatory.**
3. **Display these fields in the order admin page.**
4. **Include them in the customer and admin order email.**

Here’s a full solution you can place in your theme's `functions.php` file or a custom plugin:

### ✅ 1. Add Custom Fields to the Checkout Page

add_action('woocommerce_after_order_notes', 'custom_flower_delivery_fields');

function custom_flower_delivery_fields($checkout) {
    echo '<h3>' . __('Gift Delivery Details') . '</h3>';

    woocommerce_form_field('gift_eircode', array(
        'type'        => 'text',
        'class'       => array('form-row-wide'),
        'label'       => __('Recipient Eircode'),
        'required'    => true,
    ), $checkout->get_value('gift_eircode'));

    woocommerce_form_field('gift_phone', array(
        'type'        => 'tel',
        'class'       => array('form-row-wide'),
        'label'       => __('Recipient Phone Number'),
        'required'    => true,
    ), $checkout->get_value('gift_phone'));
}

### ✅ 2. Validate the Fields

add_action('woocommerce_checkout_process', 'custom_flower_delivery_field_validation');

function custom_flower_delivery_field_validation() {
    if (empty($_POST['gift_eircode'])) {
        wc_add_notice(__('Please enter the recipient Eircode.'), 'error');
    }

    if (empty($_POST['gift_phone'])) {
        wc_add_notice(__('Please enter the recipient phone number.'), 'error');
    }
}

### ✅ 3. Save the Fields to the Order Meta

add_action('woocommerce_checkout_create_order', 'custom_flower_delivery_field_save', 20, 2);

function custom_flower_delivery_field_save($order, $data) {
    if (!empty($_POST['gift_eircode'])) {
        $order->update_meta_data('gift_eircode', sanitize_text_field($_POST['gift_eircode']));
    }

    if (!empty($_POST['gift_phone'])) {
        $order->update_meta_data('gift_phone', sanitize_text_field($_POST['gift_phone']));
    }
}

### ✅ 4. Display Fields in Admin Order Page

add_action('woocommerce_admin_order_data_after_billing_address', 'display_gift_delivery_fields_admin', 10, 1);

function display_gift_delivery_fields_admin($order) {
    echo '<p><strong>' . __('Recipient Eircode') . ':</strong> ' . get_post_meta($order->get_id(), 'gift_eircode', true) . '</p>';
    echo '<p><strong>' . __('Recipient Phone') . ':</strong> ' . get_post_meta($order->get_id(), 'gift_phone', true) . '</p>';
}

### ✅ 5. Add Fields to Order Emails

add_filter('woocommerce_email_order_meta_fields', 'add_gift_delivery_fields_to_emails');

function add_gift_delivery_fields_to_emails($fields) {
    $fields['gift_eircode'] = __('Recipient Eircode');
    $fields['gift_phone']   = __('Recipient Phone Number');
    return $fields;
}

Let me know if you want the fields styled a specific way or conditionally shown only when a checkbox like “This is a gift” is checked.

User
Pricing changed to € from $ to all product order
Assistant
To change all WooCommerce product and order prices from **$ (USD)** to **€ (Euro)**, follow these steps:

### ✅ Step 1: **Change Currency in WooCommerce Settings**

1. Go to **WooCommerce → Settings**.
2. Under the **General** tab, scroll to the **Currency options** section.
3. Set the following:
– **Currency**: `Euro (€)`
– **Currency Position**: Choose as needed (e.g., `Left`, `Right with space`, etc.)
– **Thousand separator**, **Decimal separator**, and **Number of decimals**: Adjust if needed.

4. Click **Save changes**.

### ✅ Step 2: **Ensure Products Display in €**

If your products were priced in USD manually, you’ll need to manually adjust the prices if needed (unless you're using a currency conversion plugin):

– Go to **Products → All Products**.
– Edit each product and update the price accordingly in euros (if the numerical value should change as well).

### ✅ Optional: Automatically Convert Prices (if you need real currency conversion)

If you're migrating from USD to EUR and want automatic conversion (e.g., based on exchange rate), you can use plugins like:

– **Currency Switcher for WooCommerce** by WP Wham
– **WOOCS – Currency Switcher for WooCommerce** by realmag777

These plugins allow real-time currency conversion and display based on user location.

Let me know if you're using a multi-currency setup or want prices adjusted with a live exchange rate.

User
In block woocommere plugin
Assistant
Thanks! Since you're using the **WooCommerce Blocks plugin**, changing the currency from **$ to €** still depends on your **WooCommerce core settings**, not just the Blocks plugin itself.

Here’s how to apply the change properly for **WooCommerce Blocks**:

### ✅ 1. **Change Currency Sitewide (Affects Blocks Too)**

1. Go to your **WordPress Dashboard → WooCommerce → Settings → General**.
2. Scroll to the **Currency Options** section.
3. Set:
– **Currency**: `Euro (€)`
– **Currency Position**: Choose (e.g. `Left`, `Right with space`, etc.)
– **Decimal Separator**, **Thousand Separator**: Adjust if needed.

4. Click **Save Changes**.

> ✅ This change **automatically reflects in all WooCommerce Blocks**, including the cart, checkout, and product grid blocks.

### ✅ 2. **Check Product Prices**

If your prices were originally entered assuming **USD**, you may want to **manually update** each product’s price in Euros, unless you’re using a live currency conversion plugin.

– Go to **Products → All Products**
– Edit each product and update the **regular price** and **sale price** (if applicable)

### ✅ 3. Optional: Use Currency Switcher in Blocks

If you want customers to switch between currencies using blocks:

– Use a plugin like **WOOCS – Currency Switcher for WooCommerce** (compatible with Blocks)
– Add the **Currency Switcher Block** or shortcode using the block editor or widget

Let me know if you’re using **Multi-Currency**, **WPML**, or **custom pricing logic**, and I can tailor the steps!

User
for ch
Assistant
Got it! You want to set the **currency to Swiss Franc (CHF)** instead of Euro (€) for your WooCommerce store using **WooCommerce Blocks**.

Here’s how to properly change the pricing to **CHF (Fr.)** across your entire store, including product pages, cart, and checkout blocks:

### ✅ 1. **Set CHF as the Store Currency**

1. In your WordPress dashboard, go to:
**WooCommerce → Settings → General**
2. Scroll down to

User
for chekout fields
Assistant
Ahh gotcha — you're asking how to **customize checkout fields specifically for Switzerland (CH)** in WooCommerce, using WooCommerce Blocks, and make sure pricing reflects CHF (Fr.), *plus* apply the **custom gift delivery fields** (Eircode/phone) we discussed earlier, but tailored for Swiss users. Let’s break it down:

### ✅ Step 1: **Change Currency to CHF (Fr.)**

1. Go to **WooCommerce → Settings → General**
2. Scroll to **Currency options**
– **Currency**: `Swiss franc (CHF)`
– **Currency position**: e.g. `Left with space (Fr 100)`
– Adjust **decimal separator** or **thousands separator** if needed
3. Save Changes

✅ All WooCommerce blocks will now show **Fr.** instead of $ or €.

### ✅ Step 2: **Add Custom Checkout Fields for Gift Delivery (WooCommerce Blocks)**

Unfortunately, **WooCommerce Blocks** do **not** yet support full customization of checkout fields via standard hooks like `woocommerce_after_order_notes` used in classic checkout. So, for now you have two options:

#### 🅰️ **Option 1: Switch to Classic Checkout for Full Control**

WooCommerce lets you switch from the new block-based checkout to the **classic checkout** (which supports all `functions.php` customizations like before).

**To switch:**

1. Go to **WooCommerce → Settings → Advanced → Page Setup**
2. Under **Checkout Page**, select a page with the `[woocommerce_checkout]` shortcode (you can create a new page for this).
3. Save changes

✅ Now you can use the full PHP code from earlier to add gift delivery fields with required Eircode and phone number.

#### 🅱️ **Option 2: Add Custom Fields Using WooCommerce Checkout Field Editor Plugin**

If you want to stay with **WooCommerce Blocks** and need a no-code solution:

Use this plugin:
– 🔌 **Checkout Field Editor (by ThemeHigh)** — [Free & Pro available]
– Allows adding custom fields like “Recipient Eircode” or “Phone Number”
– Supports making fields **required**
– Fields are automatically included in admin emails and order details
– Works with block-based checkout (via compatibility)

### ✅ Step 3: Localize Field Labels for CH

Instead of “Eircode” (used in Ireland), for Switzerland, you'd likely want:

| Field | Label (CH) |
|——-|————|
| Eircode | **Postleitzahl (PLZ)** |
| Phone | **Empfänger Telefonnummer** |

### ✅ Want Me to Generate the PHP Version Using CH Labels?

If you're using the classic checkout, I can rewrite the code with the Swiss-specific labels (PLZ & phone). Want me to do that?

Leave a Comment

Your email address will not be published. Required fields are marked *