A
A
aliasst2018-05-31 09:22:29
WordPress
aliasst, 2018-05-31 09:22:29

How to change the structure of the checkout page on woocommerce?

On the checkout page, you need to change the html structure of the delivery method selection block.
5b0f9294c18c6377995287.png
By default, the block has the following html table structure:

<table>
    <tr>
         <th>Доставка</th>
  <td>
    <ul>
      <li>Способ 1</li>
      <li>Способ 2</li>
      <li>Способ 3</li>
      <li>Способ 4</li>
    </ul>
  </td>
</tr>
</table>

And you need to make it just blocks and lists without tables.
The review-order.php template is responsible for the output of this block,
namely, in this function: and here is the code of this function:<?php wc_cart_totals_shipping_html(); ?>
function wc_cart_totals_shipping_html() {
  $packages = WC()->shipping->get_packages();
  $first    = true;

  foreach ( $packages as $i => $package ) {
    $chosen_method = isset( WC()->session->chosen_shipping_methods[ $i ] ) ? WC()->session->chosen_shipping_methods[ $i ] : '';
    $product_names = array();

    if ( count( $packages ) > 1 ) {
      foreach ( $package['contents'] as $item_id => $values ) {
        $product_names[ $item_id ] = $values['data']->get_name() . ' &times;' . $values['quantity'];
      }
      $product_names = apply_filters( 'woocommerce_shipping_package_details_array', $product_names, $package );
    }

    wc_get_template(
      'cart/cart-shipping.php', array(
        'package'                  => $package,
        'available_methods'        => $package['rates'],
        'show_package_details'     => count( $packages ) > 1,
        'show_shipping_calculator' => is_cart() && $first,
        'package_details'          => implode( ', ', $product_names ),
        /* translators: %d: shipping package number */
        'package_name'             => apply_filters( 'woocommerce_shipping_package_name', ( ( $i + 1 ) > 1 ) ? sprintf( _x( 'Shipping %d', 'shipping packages', 'woocommerce' ), ( $i + 1 ) ) : _x( 'Shipping', 'shipping package', 'woocommerce' ), $i, $package ),
        'index'                    => $i,
        'chosen_method'            => $chosen_method,
      )
    );

    $first = false;
  }
}

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