• Resolved Haja

    (@hajakutbudeen)


    Hello there,

    In my site we have custom form option in checkout need o update label and price into order section based on user input
    Ex:
    In checkout we added option standard/premium
    When ever user select standard we need to add label Standard into order section and add price 10 USD, if user select premium then we need to update the value and price. we need to send this information in email also

    • This topic was modified 3 years, 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • Are you using WooCommerce? If so, here is more info about adding custom fields to the checkout page from their documentation.

    Hope this helps.

    Thread Starter Haja

    (@hajakutbudeen)

    Hello @binarywc,

    Yes i am using woo-commerce, please check below link for my sample checkout i add my custom fields into checkout area, i want to know when i make changes in custom fields its need to be add in Your order section. the custom field data need to be save in db it needs to display in admin panel order section. May i know hooks and simple example for that please
    ref:
    https://i.postimg.cc/632rQLR4/Screen-Shot-2021-12-29-at-9-53-44-AM.png

    That depends on how you add the fields. If you are following the steps mentioned in the article I posted yesterday you will be better off asking these questions to WooCommrece Support. The thread is in the General WP support area and I have personally never needed to add custom fields to the checkout so I do not have experience with this.

    Thread Starter Haja

    (@hajakutbudeen)

    Hello @binarywc,

    Thanks for your reply and your time. really appreciated. I’ve found what i am looking for i just paste code for ref. Thank you

    // Add custom checkout datepicker field
    add_action( ‘woocommerce_after_checkout_billing_form’, ‘datepicker_custom_field’ );
    function datepicker_custom_field($checkout) {
    $datepicker_slug = ‘my_datepicker’;
    echo ‘<div id=”datepicker-wrapper”>’;
    woocommerce_form_field($datepicker_slug, array(
    ‘type’ => ‘text’,
    ‘class’=> array( ‘form-row-first my-datepicker’, ‘update_totals_on_change’),
    ‘label’ => __(‘My Custom Date-picker’),
    ), ” );
    woocommerce_form_field( ‘tip’, array(
    ‘type’ => ‘radio’,
    ‘class’ => array( ‘form-row-wide’, ‘update_totals_on_change’ ),
    ‘options’ => array(
    ‘5’ => ‘5’,
    ’10’ => ’10’,
    ’15’ => ’15’,
    ),
    ));
    echo ‘<br clear=”all”></div>’;
    // Jquery: Enable the Datepicker
    ?>
    <script language=”javascript”>
    jQuery( function($){
    var a = ‘#<?php echo $datepicker_slug ?>’;
    jQuery(a).datepicker({
    dateFormat: ‘yy-mm-dd’, // ISO formatting date
    });
    });
    </script>
    <?php
    }

    // adds a custom fee based on the field valued
    add_action( ‘woocommerce_cart_calculate_fees’, ‘update_custom_fields’, 10, 1 );
    function update_custom_fields( $cart ) {

    if ( ! $_POST || is_admin() || ! is_ajax() ) {
    return;
    }

    if ( isset( $_POST[‘post_data’] ) ) {
    parse_str( $_POST[‘post_data’], $post_data );
    } else {
    $post_data = $_POST;
    }

    if ( isset( $post_data[‘my_datepicker’] ) ) {
    if($post_data[‘my_datepicker’]){
    WC()->cart->add_fee( ‘Schedule a Fitment Date – ‘.$post_data[‘my_datepicker’], false );
    }
    }

    if ( isset( $post_data[‘tip’] ) ) {
    $percentage = $post_data[‘tip’];
    WC()->cart->add_fee( ‘Tip’, $percentage, true );
    }
    }`

    Wonderful! Glad you found a solution. Feel free to post here any time for more help. In the meantime, please go ahead and change the status of this thread to resolved for me on the right side of the page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add custom field into checkout page’ is closed to new replies.