Your cart is currently empty!
[WooCommerce] วิธีเพิ่ม Field Checkout ใน WooCommerce
จริง ๆ ถ้าเอาแบบง่าย ๆ WooCommerce จะมีปลั๊กอินขายอยู่แล้ว แต่แอบแพง ; w ; เขียนใน functions.php เองก็ได้
การเพิ่ม Field ในหน้า Checkout
WooCommerce มี Feature ให้ hook เข้าไปอยู่แล้ว สามารถ hook ใส่ Shipping Field หรือ Field ธรรมดาก็ได้ (สังเกต $fields[‘shipping’] ใน Code ข้างล่าง
// WooCommerce - Add Shipping Fields
add_filter( 'woocommerce_checkout_fields' , 'add_field_checkout_fields' );
function add_field_checkout_fields( $fields ) {
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-first')
);
$fields['shipping']['shipping_mail'] = array(
'label' => __('Email Address', 'woocommerce'),
'placeholder' => _x('Email Address', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => true
);
return $fields;
}
Reference: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
วิธีการ Reorder Fields
add_filter("woocommerce_checkout_fields", "order_fields");
function order_fields($fields) {
$order = array(
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_address_1",
"billing_address_2",
"billing_postcode",
"billing_country",
"billing_email",
"billing_phone"
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
return $fields;
}ph
by
Tags:
Leave a Reply