[WordPress] 外掛分享: F4 Simple Checkout Fields for WooCommerce

首頁外掛目錄 › F4 Simple Checkout Fields for WooCommerce
WordPress 外掛 F4 Simple Checkout Fields for WooCommerce 的封面圖片
10+
安裝啟用
★★★★★
5/5 分(1 則評價)
80 天前
最後更新
問題解決
WordPress 5.0+ PHP 7.0+ v1.0.16 上架:2019-03-01

內容簡介

使用 F4 Simple Checkout Fields for WooCommerce 插件,您可以簡單地為 WooCommerce 結帳頁面添加新的欄位。插件沒有 UI 管理欄位,只能透過簡單的 PHP 方法添加欄位。這保證了插件輕量且易於處理,但需要一些 PHP 知識和存取檔案系統的權限來添加程式碼(建議使用您的 WordPress 主題)。

使用方式

如果您第一次安裝此插件,它將不會產生任何作用。但它提供了一種方法,可以為您的結帳頁面添加任意數量的自訂欄位。下面是一個範例,展示如何為帳單地址和送貨地址添加一個簡單的文字欄位:

add_action('init', function() {
F4\WCSCF\Core\Helpers::register_field(array(
'name' => 'demo-text',
'type' => 'text',
'label' => 'Text Field'
));
});

引數

register_field 方法提供了很多引數來自訂您的欄位。其中一些引數與 官方 WooCommerce 引數 非常相似:

F4\WCSCF\Core\Helpers::register_field(array(
// (array) 定義欄位應添加到哪裡
// billing = 帳單地址,shipping = 送貨地址
'target' => array('billing', 'shipping'),

// (string) 欄位內部名稱。必須唯一
'name' => '',

// (string) 欄位類型(text、textarea、password、select)
'type' => 'text',

// (string) 欄位標籤
'label' => '',

// (string) 欄位說明
'description' => '',

// (string) 輸入框預設文字(僅限 text、textarea 和 password)
'placeholder' => '',

// (boolean) 定義欄位是否為必填欄位
'required' => false,

// (string) 預設值
'default' => '',

// (array) CSS 類別陣列,用於添加至該欄位
'class' => array(),

// (array) 欄位選項陣列(僅限 select 欄位)
// Array key => value pairs: array('value' => 'Label')
'options' => array(),

// (string|array) 定義欄位應加入的位置
// last = 在最後一個欄位後新增
// first = 在第一個欄位前新增
// array('before' => 'fieldname') = 在所定義欄位之前新增
// array('after' => 'fieldname') = 在所定義欄位之後新增
'position' => 'last', // 'first', 'last', array('before' => ''), array('after' => '')

// (string) 格式化地址輸出時使用的分隔符號
'formatted_address_delimiter' => "\n",

// (boolean) 定義欄位是否顯示於訂單後台格式化地址之後
'show_after_formatted_admin_order_address' => false,

// (boolean) 定義欄位標籤是否應在格式化地址之前輸出
'show_formatted_address_label' => false,

// (boolean) 定義欄位是否顯示於帳單地址表單
'show_in_address_form' => true,

// (boolean) 定義欄位是否顯示於結帳表單
'show_in_order_form' => true,

// (boolean) 定義欄位是否顯示於格式化地址之中
'show_in_formatted_address' => true,

// (boolean) 定義欄位是否顯示於我的帳戶地址表單
'show_in_account_address' => true,

));

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.16) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「F4 Simple Checkout Fields for WooCommerce」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

With F4 Simple Checkout Fields for WooCommerce you can simply add new fields to the WooCommerce checkout. There is no UI to manage the fields, they only can be added with a simple PHP method. That ensures that the plugin is lightweight and easy to handle, even though you need simple PHP knowledge and access to the file system to add the code (preferred your WordPress theme).
Usage
If you first install this plugin, it will do nothing. But it provides a method to add as many custom fields to your checkout as you need. Here’s a sample how you could add a simple text field to the billing and shipping address:
add_action('init', function() {
F4\WCSCF\Core\Helpers::register_field(array(
'name' => 'demo-text',
'type' => 'text',
'label' => 'Text Field'
));
});

Arguments
The register_field method provides a lot of arguments to customize your fields. Some of the arguments are identically to the officiel WooCommerce arguments:
F4\WCSCF\Core\Helpers::register_field(array(
// (array) Defines where the field should be added
// billing = billing address, shipping = shipping address
'target' => array('billing', 'shipping'),

// (string) The internal name for the field. Must be unique
'name' => '',

// (string) The field type (text, textarea, password, select)
'type' => 'text',

// (string) The field label
'label' => '',

// (string) The description
'description' => '',

// (string) The placeholder for the input (only text, textarea or password)
'placeholder' => '',

// (boolean) Defines if the field is required or not
'required' => false,

// (string) The default value
'default' => '',

// (array) An array with css classes that should be added to the field
'class' => array(),

// (array) An array with field options (only for field type select)
// Array key => value pairs: array('value' => 'Label')
'options' => array(),

// (string|array) Defines the position, where the field should be added
// last = append after the last field
// first = prepend before the first field
// array('before' => 'fieldname') = prepend before the defined field
// array('after' => 'fieldname') = append after the defined field
'position' => 'last', // 'first', 'last', array('before' => ''), array('after' => '')

// (string) The delimiter that should be used in the formatted address outputs
'formatted_address_delimiter' => "\n",

// (boolean) Defines if the field should be displayed after the formatted address in the order backend or not
'show_after_formatted_admin_order_address' => false,

// (boolean) Defines if the field label should be prepended before the field value in formatted address
'show_formatted_address_label' => false,

// (boolean) Defines if the field should be displayed in the account address forms
'show_in_address_form' => true,

// (boolean) Defines if the field should be displayed in the checkout forms
'show_in_order_form' => true,

// (boolean) Defines if the field should be displayed in the formatted address
'show_in_formatted_address' => true,

// (boolean) Defines if the field should be displayed in the admin user form
'show_in_admin_user_form' => true,

// (boolean) Defines if the field should be displayed in the admin order form
'show_in_admin_order_form' => true,

// (boolean) Defines if the field should be displayed in the privacy customer data
'show_in_privacy_customer_data' => true,

// (boolean) Defines if the field should be displayed in the privacy order data
'show_in_privacy_order_data' => true
));

Features overview

Adds custom text, textarea, password and select fields to the checkout
Easy to use
Lightweight and optimized
100% free!

Planned features

Full integration into API and REST

延伸相關外掛

文章
Filter
Apply Filters
Mastodon