zmena názvu, placeholderu, zmena pozície či odstránenie pola
<?php
function my_custom_woocommerce_checkout_fields( $fields )
{
$fields['order']['order_comments']['placeholder'] = 'placeholder';
$fields['order']['order_comments']['label'] = 'nazov';
$fields['billing']['billing_company_wi_id']['label'] = 'nazov ';
$fields[ 'billing' ][ 'billing_ic' ][ 'priority' ] = 90; // zmena pozície
$fields[ 'billing' ][ 'billing_company' ][ 'priority' ] = 85;
unset($fields['billing']['billing_last_name']); // odstránenie / skrytie pola
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'my_custom_woocommerce_checkout_fields' );
presun do inej skupiny polí (s tým istým popisom)
add_filter( 'woocommerce_checkout_fields', 'billing_email_another_group' );
function billing_email_another_group( $checkout_fields ){
// 1. We assign a field array to another group here
$checkout_fields[ 'order' ][ 'billing_email' ] = $checkout_fields[ 'billing' ][ 'billing_email' ]; // nove / stare
// 2. Remove a field from a previous location
unset( $checkout_fields[ 'billing' ][ 'billing_email' ] );
return $checkout_fields;
}
Viac na: https://rudrastyh.com/woocommerce/reorder-checkout-fields.html
Podmienky pre úpravu polí
add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields',90);
function custom_override_checkout_fields($fields)
{
unset($fields['billing']['billing_address_2']);
$fields['billing']['billing_first_name']['label'] = 'Prve meno';
if ( isset($_POST['billing_company']) && !empty($_POST['billing_company']) && ($_POST['wi_as_company']) == true ){
$fields['billing']['billing_first_name']['required'] = false;
$fields['billing']['billing_last_name']['required'] = false;
}
Ak by ste chceli pridať poľu atribút môžete to urobiť takto:
$fields['billing']['billing_phone']['maxlength'] = 10;
Ak chceme nastaviť max. dĺžku inputu stačí pridať toto.
V predvolenom nastavení platobné polia WooCommerce totiž podporujú nasledujúce atribúty polí:
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'id' => $key,
'class' => array(),
'label_class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);
Ako pridať atribút ktorý Woocomerce nepodporuje nájdete v tomto článku.