I’ve spent way too much time trying to get this working and I’m fairly confident the issue has two be right in front of me so I’m hoping someone can help me.
I’m trying to add custom fields to my checkout form and everything works except the radio buttons which keep wrapping.
Background
WP: 6.7.1
Bricks: 1.11.1
- I’m using this Brixies layout.
- I’m using this guide for creating the following code.
- My checkout page
My code
I’ve added this to my functions.php:
function gift_checkout_field( $checkout ) {
echo '<div id="gift_checkout_field"><h2>' . esc_html__( 'Gift information' ) . '</h2>';
woocommerce_form_field(
'is_gift',
array(
'type' => 'radio',
'class' => array( 'my-field-class form-row-wide' ),
'label' => __( 'Is this a gift order?' ),
'options' => array(
'' => 'No',
'1' => 'Yes, this is a gift'
),
'style' => 'width:16px',
),
$checkout->get_value( 'is_gift' )
);
woocommerce_form_field(
'gift_wrap',
array(
'type' => 'radio',
'class' => array( 'my-field-class form-row-wide' ),
'label' => __( 'Gift wrap' ),
'options' => array(
'' => 'No',
'1' => 'Yes, basic gift wrap'
),
'style' => 'width:16px',
),
$checkout->get_value( 'gift_wrap' )
);
woocommerce_form_field(
'gift_name',
array(
'type' => 'text',
'class' => array( 'my-field-class form-row-wide' ),
'label' => __( 'Recipient name' ),
'placeholder' => __( 'Who is the gift for...' )
),
$checkout->get_value( 'gift_name' )
);
woocommerce_form_field(
'gift_message',
array(
'type' => 'textarea',
'class' => array( 'my-field-class form-row-wide' ),
'label' => __( 'Gift message' ),
'placeholder' => __( 'Enter a message to the recipient...' )
),
$checkout->get_value( 'gift_message' )
);
echo '</div>';
}
This is the CSS code that came with the Brixies layout.
/* -- The root styles must go in the element of the structure with the name "Checkout"(Section). --*/
.woocheckout {
/* Form details */
.woocheckout__form-details {
h3 {
margin-bottom: var(--space-s);
}
/* Checkout form styles*/
.form-row {
margin-bottom: var(--space-s);
}
#ship-to-different-address label{
width: 100%;
padding-inline-end: var(--space-m);
}
.checkbox{
border: none;
}
/* Inputs styles */
.input,
input:not([type=submit]),
select,
textarea {
border: 1px solid var(--dark-20);
border-radius: var(--radius-xs);
padding: var(--space-xs);
&:focus {
border-color: var(--dark);
}
}
/* 2 column field styles */
.form-row-first,
.form-row-last {
width: calc(50% - var(--space-m)/2);
@media (max-width: 991px) {
width: 100%;
}
}
}
/* Default values of woocommerce fields */
.form-row-first{
float:left;
}
.form-row-last{
float:right;
}
.form-row-wide{
clear:both;
}
/* Select2 field styles (Region / Département) */
.select2-container--default .select2-selection--single{
border: 1px solid var(--dark-20);
border-radius: var(--radius-xs);
padding: var(--space-xs);
height:auto;
}
/* Select2 field arrow styles */
.select2-container--default .select2-selection--single
.select2-selection__arrow{
top:50%;
}
}
.free-shipping {
row-gap: var(--space-3xs);
}
/* Checkout order details*/
.woocheckout__order-review {
#order_review, thead, tfoot{
border: none;
}
/* Review order table styles */
.woocommerce-checkout-review-order-table{
background-color: var(--dark-10);
border-radius: var(--radius-m);
border: none;
.cart-subtotal{
border-bottom: 1px solid var(--dark-10);
}
/* Table heading styles */
thead th{
padding: var(--space-m) var(--space-m) var(--space-xs) var(--space-m);
}
/* Table body styles */
tbody td{
padding: var(--space-xs) var(--space-m);
}
/* Table footer (total price) styles */
tfoot :is(td, th){
padding: var(--space-m);
}
}
/* Checkout payment styles */
.woocommerce-checkout-payment{
border-radius: var(--radius-m);
.payment_box {
border-radius: var(--radius-s);
}
}
/*- Terms and conditions style -*/
.woocommerce-form__label-for-checkbox{
font-size: var(--text-s);
margin-top: var(--space-s);
font-weight: 600;
color: var(--dark);
display: block;
border: none;
width: 100%;
height: auto;
}
}
}
Please and thank you!!