/    Sign up×
Community /Pin to ProfileBookmark

Force WooCommerce shipping field to display with billing info

I’m trying to get the WooCommerce shipping fields to display without requiring the user to have to re-enter all their info from the billing section. I have the WooCommerce/checkout/form-shipping.php file copied over to my child theme, and I’ve been playing around with the checkbox. But every time it is checked, it erases all the billing info.

Does someone have a suggestion?

to post a comment

6 Comments(s)

Copy linkTweet thisAlerts:
@NtrimgsauthorSep 13.2022 — For some reason I can't post the code. It says I don't have permission.

Copy linkTweet thisAlerts:
@SempervivumSep 13.2022 — Unfortunately the forum software blocks script tags of HTML, both PHP or javascript. You can work around this by omitting the tags or modifying them, e. g. like this for javascript:

`<_script> code here <_/script>`

Apart from this, occasionally the software displays the message
>You are not allowed to do this

You can ignore this and click the close button.
Copy linkTweet thisAlerts:
@NtrimgsauthorSep 14.2022 — Ok, let me try this:

&lt;div class="woocommerce-shipping-fields"&gt;<br/>
&lt;<STRONG>__?php if ( true === WC()-&gt;cart-&gt;needs_shipping_address() ) : ?__</STRONG>&gt;

<i> </i><CODE> &lt;h3 id="ship-to-different-address"&gt;
<i> </i> &lt;label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox"&gt;
<i> </i> &lt;input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" &lt;__?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?__&gt; type="checkbox" name="ship_to_different_address" value="1" /&gt; &lt;span&gt;&lt;__?php esc_html_e( 'Ship to a different address?', 'woocommerce' ); ?__&gt;&lt;/span&gt;
<i> </i> &lt;/label&gt;
<i> </i> &lt;/h3&gt;

<i> </i> &lt;div class="shipping_address"&gt;

<i> </i> &lt;__?php do_action( 'woocommerce_before_checkout_shipping_form', $checkout ); ?__&gt;

<i> </i> &lt;div class="woocommerce-shipping-fields__field-wrapper"&gt;
<i> </i> &lt;__?php
<i> </i> $fields = $checkout-&gt;get_checkout_fields( 'shipping' );

<i> </i> foreach ( $fields as $key =&gt; $field ) {
<i> </i> woocommerce_form_field( $key, $field, $checkout-&gt;get_value( $key ) );
<i> </i> }
<i> </i> ?__&gt;
<i> </i> &lt;/div&gt;

<i> </i> &lt;__?php do_action( 'woocommerce_after_checkout_shipping_form', $checkout ); ?__&gt;

<i> </i> &lt;/div&gt;

<i> </i>&lt;__?php endif; ?__&gt;</CODE>
&lt;/div&gt;
`
Copy linkTweet thisAlerts:
@NtrimgsauthorSep 14.2022 — Here's part of the code. This is the code that displays the "Ship to a different address" checkbox on the WooCommerce shipping section. By default, it's unchecked - already filled with the billing info. But in this state, the shipping information doesn't display. With the code below, I made it checked, which does display the shipping info, but it also removes all the pre-filled billing info. And I'm trying to have it do both: display shipping info AND have fields pre-filled with billing info.

&lt;h3 id="ship-to-different-address"&gt;<br/>
&lt;label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox"&gt;<br/>
&lt;input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" &lt;__?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?__&gt; type="checkbox" name="ship_to_different_address" value="1" **checked**/&gt; &lt;span&gt;&lt;__?php esc_html_e( 'Ship to a different address?', 'woocommerce' ); ?__&gt;&lt;/span&gt;<br/>
&lt;/label&gt;<br/>
&lt;/h3&gt;
Copy linkTweet thisAlerts:
@NtrimgsauthorSep 14.2022 — Here is the portion of code just beneath the checkbox code (shown above), that populates the shipping fields.

$fields = $checkout-&gt;get_checkout_fields( 'shipping' );

<i> </i><CODE>foreach ( $fields as $key =&gt; $field ) {
<i> </i>woocommerce_form_field( $key, $field, $checkout-&gt;get_value( $key ) );
<i> </i>}</CODE>


And all this code is wrapped in a conditional statement:

if ( true === WC()-&gt;cart-&gt;needs_shipping_address() ) :
Copy linkTweet thisAlerts:
@marionlankfordSep 16.2022 — Hello sir

Follow the given steps

By Using AIO Checkout Plugin

-Install and Activate the AIO Checkout Plugin

-Navigate to the AIO Checkout

-Create a New Checkout Form

-Hide the Shipping Details Section

-Change the Label of the Billing Section
  • - Change the Label

    -Select the Design of the Checkout Form

    -Enable the Checkout Form

    -Give a Name to the Form

    -Save Changes

    -Final Results
  • ×

    Success!

    Help @Ntrimgs spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 3.28,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,

    tipper: Anonymous,
    tipped: article
    amount: 10 SATS,
    )...