D
D
damarkuzz2021-11-23 22:46:48
WordPress
damarkuzz, 2021-11-23 22:46:48

How to dynamically load information from input when placing an order?

How to dynamically load the entered information from the input floor_countwhen placing an order (checkout) in order to then substitute it into the $floor_count variable and recalculate the price?

add_action( 'woocommerce_review_order_before_payment', 'truemisha_checkout_options', 25 );
  function truemisha_checkout_options() {
    // сначала получаем объект из сессий
    $selected = WC()->session->get( 'gift_wrap' );
    // если пусто, то ставим значение 0
    $selected = empty( $selected ) ? '0' : $selected;
    
    //выводим текстовый input
    woocommerce_form_field(
      'floor_count',
      array(
        'type' => 'text',
        'class' => array( 'text_floor'),
      )
    );
    
    // выводим радио-кнопки
    woocommerce_form_field(
      'gift_wrap',
      array(
        'type' => 'radio',
        'class' => array( 'form-row-wide', 'update_totals_on_change' ),
        'options' => array(
          '0' => 'Подъем на этаж не нужен',
          ''.$floor_count.'' => 'Включить подъем на этаж + ( 100 кг x 5 руб/этаж)',
        ),
      ),
      $selected 
    );
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question