Woocommerce new fields - wordpress

How can I add 2 new fields on the same row? Now They are on 2 rows.
add_filter('woocommerce_checkout_fields','reorder_woo_fields');
function reorder_woo_fields($fields) {
$fields2['billing']['billing_ico'] = array(
'label' => __('ICO', 'woocommerce'),
'placeholder' => _x('ICO', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-first'),
'clear' => true
);
$fields2['billing']['billing_dic'] = array(
'label' => __('DIC', 'woocommerce'),
'placeholder' => _x('DIC', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-last'),
'clear' => true
);
return $fields2;
}
Cheers.

Use your class names form-row-first & form-row-last in CSS and set them to a specified width and display inline.

Related

According to the payment method, display the information that needs to be filled in

I have a different payment methods,
How can, according to the payment method, display the information that needs to be filled in on the Checkout Page?
For Example, when choose Credit Card, will show Input box in Billing area
add_filter( 'woocommerce_checkout_fields', "custom_override_checkout_fieldss");
function custom_override_checkout_fieldss( $fields ) {
$fields['billing']['card_type'] = [
'type' => 'text',
'label' => 'Card Numner',
'required' => true,
'placeholder' => _x('Card Numner', 'placeholder', 'woocommerce'),
'priority' => -3,
];
$fields['billing']['card_type_code'] = [
'type' => 'text',
'label' => 'code',
'required' => true,
'placeholder' => _x('CVV2', 'placeholder', 'woocommerce'),
'priority' => -2,
];
$fields['billing']['card_type_num'] = [
'type' => 'text',
'label' => 'date',
'required' => true,
'placeholder' => _x('expired date', 'placeholder', 'woocommerce'),
'priority' => -1,
];
return $fields;
};

Adding a new custom shipping field in woocommerce

I'd like to add a new custom billing field in my woocommerce checkout. After adding the following code inside my child theme functions.php, saved it and refreshed the page, I received a blank page. There was no error message. I believe there must be syntax error or something.
add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');
function custom_override_checkout_fields($fields) {
$fields['shipping']['about_yourself'] = array(
'label' => __('About yourself', 'woocommerce'),
'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide');
'clear' => true
);
return $fields;
}
I was wondering if anyone could help me out.
Thank you in advance
The error is in your array field that should be like:
$fields['shipping']['about_yourself'] = array(
'label' => __('About yourself', 'woocommerce'),
'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
NOTE: During development process to enable the error_reporting() and set WP_DEBUG true. This is how you enable it during WordPress development in wp-config.php file
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
#ini_set('display_errors', 0);
You have added ; instead of , in 'class' => array('form-row-wide');
So your code would be :
add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');
function custom_override_checkout_fields($fields) {
$fields['shipping']['about_yourself'] = array(
'label' => __('About yourself', 'woocommerce'),
'placeholder' => _x('About yourself', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}

woocommerce Customising checkout fields

I am trying to customise the woocommerce checkout page. The below works fine:
$fields['billing']['billing_city'] = array(
'label' => __('Town / City:', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'label_class' => array('infotown'),
'clear' => true,
'placeholder' => _x('', 'placeholder')
);
Where as the following does not:
$fields['billing']['billing_state'] = array(
'label' => __('State:', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'label_class' => array('infocounty'),
'clear' => true,
'placeholder' => _x('', 'placeholder')
);
There's no difference between the 2, apart from the label, and the label class.
Any ideas?
try adding
- woocommerce language support, which is for translators
- check the add_action function in which you are adding it too
- spacing can be a problem in the wrong places also
to add language support, try so
$fields['billing']['billing_state'] = array(
'label' => __('State:', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'label_class' => array('infocounty'),
'clear' => true,
'placeholder' => _x('', 'placeholder', 'woocommerce')
);
where i added "woocommerce" next to placeholder. :)

How to add a select custom field to checkout page in WooCommerce?

I'm adding extra fields to the checkout page in WooCommerce,
I've added basic text fields ok, but I want a dropdown or select box with a few options,
Here is what I've done so far but I've made an error somewhere
$fields['billing']['billing_meat'] = array(
'label' => __('Food options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false
'type' => 'select',
'options' => array( // array of key => value pairs for select options
__('I eat meat', 'woocommerce') => __('I eat mate', 'woocommerce'),
__('meat is gross', 'woocommerce') => __('meat is gross', 'woocommerce'),
Maybe I'm not defining 'type' field correctly?
thanks loads
If that is your exact code, then the problem is that you are missing a comma after 'clear' => false.
I've tested this and it works:
$fields['billing']['billing_meat'] = array(
'label' => __('Food options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => array(
'eat-meat' => __('I eat maet', 'woocommerce' ),
'not-meat' => __('Meat is gross', 'woocommerce' )
)
);
Note that I also did not use __() on the options array keys. It's better to not translate those.
this is working. here's my code
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'dropdown' );
// Our hooked in function - $fields is passed via the filter!
function dropdown( $fields ) {
$fields['billing']['dropdown'] = array(
'label' => __('dropdown', 'woocommerce'),
'placeholder' => _x('dropdown', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
'type' => 'select',
'options' => array(
'option 1' => __('option 1', 'woocommerce' ),
'option 2' => __('option 2', 'woocommerce' )
)//end of options
);
return $fields;
}
this works. but it seems that the value is not being saved under _billing_dropdown. I used "admin columns" plugin to add a field in the order table (admin side). under my custom field "dropdown", no value shows up. where can i retrieve the value? same goes with my other custom field "purpose" that is under "_billing_purpose" and is type=>'textarea'. thanks!
here's a screenshot
https://scontent-b-hkg.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/10696182_985415141473105_5302358697439449940_n.jpg?oh=74cb5ebc6b1ad6dd0c29e51293b61fdf&oe=5502613C

How to make checkbox checked?

I have this field in form builder
->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
),
'expanded' => true,
'label' => 'Способ оплаты',
))
with ony one option yet, but how can i make this checked?
Add attr index with 'checked' => 'checked':
->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
),
'expanded' => true,
'label' => 'Способ оплаты',
'attr' => array('checked' => 'checked')
))
Set it on the object or array the form is used for.
You can set the default value by either setting it in your domain model:
private $pay_method = 'telnet';
or
$object->pay_method = 'telnet'
or by specifying the "data" option of the field:
$builder->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
...
),
'data' => 'telnet',
'expanded' => true,
'label' => ...,
));
Ok, i did it through JavaScript

Resources