skip to Main Content

I want to move the shipping options from the order review table before the payment options in the checkout.

I saw, that the order review table has its own template file review-order.php.
There I found the following code:

<?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>

    <?php do_action( 'woocommerce_review_order_before_shipping' ); ?>

    <?php wc_cart_totals_shipping_html(); ?>

    <?php do_action( 'woocommerce_review_order_after_shipping' ); ?>

<?php endif; ?>

I know that I could reorder the content from woocommerce_review_order_before_shipping and woocommerce_review_order_after_shipping with an hook.
But the code starts with an if clause.

So I’m not sure if or how I could move that section to another place in the checkout.

Is there a way I don’t see?

2

Answers


  1. You can cut the entire code block and then paste it into another template file within the checkout folder

    So cut from the checkout/review-order.php template file line L67-L75

    <?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>
    
        <?php do_action( 'woocommerce_review_order_before_shipping' ); ?>
    
        <?php wc_cart_totals_shipping_html(); ?>
    
        <?php do_action( 'woocommerce_review_order_after_shipping' ); ?>
    
    <?php endif; ?>
    

    To line 51 in the checkout/form-checkout.php template file

        ...
        <?php do_action( 'woocommerce_checkout_after_customer_details' ); ?>
    
    <?php endif; ?>
    
    <!-- PASTE HERE -->
    
    <?php do_action( 'woocommerce_checkout_before_order_review_heading' ); ?>
    
    <h3 id="order_review_heading"><?php esc_html_e( 'Your order', 'woocommerce' ); ?></h3>
    ...
    
    Login or Signup to reply.
  2. Adding to the answer from @7uc1f3r

    You can cut the entire code block and then paste it into another template file within the checkout folder

    You can add your plugin’s templates folder to WooCommerce’s templates search filter, that way you can have your WooCommerce templates in your plugin directory, use the following function:

    /**
     * Add plugin's templates folder to WooCommerce template locations  
     */
     function af_plugin_templates($template, $template_name, $template_path)
    {
        global $woocommerce;
        $_template = $template;
        if (!$template_path)
            $template_path = $woocommerce->template_url;
    
        $plugin_path  = plugin_dir_path( __FILE__ ) . 'templates/woocommerce/';
    
        // First check if our plugin has the template
        $file = file_exists($plugin_path . $template_name);
        if ($file)
            $template = $plugin_path . $template_name;
    
        // Look within passed path within the theme
        if (!$template)
            $template = locate_template(
                array(
                    $template_path . $template_name,
                    $template_name
                )
            );
    
        if (!$template)
            $template = $_template;
    
        return $template;
    }
    add_filter('woocommerce_locate_template',af_plugin_templates', 1, 3);
    

    Now you can add your templates in ‘your_plugin/templates/woocommerce/…’ directory and they will be prioritized.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search