Ad

Move Product Section To Top When On Mobile On WooCommerce Checkout

I'm trying to move the product section to the top when on mobile on WooCommerce Checkout. I do not want the the billing section to be on top.

I tried with the following, without success:

add_action('wp_footer', 'mobile_checkout');
function mobile_checkout() {
    if ( wp_is_mobile() && is_checkout() ) {
        remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
        add_action( 'woocommerce_before_checkout_billing_form', 'woocommerce_order_review', 1 );
    }
}

Any ideas on how to move it?

Ad

Answer

This should suffice:

function action_woocommerce_before_checkout_billing_form() {
    // Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
    if ( wp_is_mobile() ) {
        remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
        add_action( 'woocommerce_before_checkout_billing_form', 'woocommerce_order_review', 5 );
    }
}
add_action( 'woocommerce_before_checkout_billing_form', 'action_woocommerce_before_checkout_billing_form', 1 );
Ad
source: stackoverflow.com
Ad