• Hello! I’m trying to add some custom fields to the WooCommerce checkout form. Currently, I’m using the woocommerce_checkout_fields hook which is usually easy – for a radio I can add:

    $fields['billing']['_click_yes'] = array(
    	'type'			=> 'radio',
    	'label'			=> 'Click Yes',
    	'required'		=> 0,
    	'class'			=> array(
    		'form-row-first',
    		'custom-field',
    		'input-radio',
    	),
    	'options'		=> array(
    		'Yes'	=> ' Yes',
    		'No'	=> ' No',
    	),
    );

    And I can do something similar for a select dropdown list. The issue is checkboxes don’t appear to follow the same rules ( or I’m missing something obvious ). Here’s what I’m using for checkboxes:

    $fields['billing']['_weekdays'] = array(
    	'type'			=> 'checkbox',
    	'label'			=> 'Days of The Week',
    	'required'		=> 0,
    	'class'			=> array(
    		'form-row-last',
    		'custom-field',
    		'input-checkbox',
    	),
    	'options'		=> array(
    		'Monday'	=> 'Monday',
    		'Tuesday'	=> 'Tuesday',
    		'Wednesday'	=> 'Wednesday',
    		'Thursday'	=> 'Thursday',
    		'Friday'	=> 'Friday',
    		'Saturday'	=> 'Saturday',
    		'Sunday'	=> 'Sunday',
    	),
    );

    What ends up appearing is the label parameter is shown with a checkbox before the text instead of the main title and the options all being checkboxes. Is there something I’m missing or is it just not capable of this yet?

    https://ww.wp.xz.cn/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Checkboxes are individual fields. You can select more than one checkbox, so they need to be saved separately.

    options do not work for checkboxes. The value will just be ‘1’ if it is checked.

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    Just re-ran across this topic while trying to do the same thing.

    Is there no way to group checkboxes then in the WooCommerce system?

    The scenario is that I have users registering for an account and I’m saving custom data to their user, one of which is a group of checkboxes they can select to be assigned specific options later down the road. If I create each one separately, wouldn’t they be all on their own lines and thus ungrouped and more difficult to save?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Checkout Fields – Checkboxes’ is closed to new replies.