Combined WooCommerce Checkout/Cart page and adding cross-sell

I’ve combined the shortcodes for checkout and cart onto the Checkout page in two columns to reduce the number of clicks to finish payment.

However, I’m finding that hooks seem to act strangely with this arrangement.

For example, I’m trying to place the cross-sell section below the cart section. On the default cart page, it appears by default. Combining cart and checkout together makes it disappear.

The logical approach is to do this:

function add_cart_collaterals() {
    if (is_checkout()) {
        add_action( 'woocommerce_after_cart_contents', 'woocommerce_cross_sell_display' );
add_action('wp', 'add_cart_collaterals');

That did nothing.

Out of desperation, I then copied and adapted the cross-sell.php template code and put it directly into my child theme’s functions.php file like this:

/* Display Cross-Sells below cart */
function show_cross_sell() {
    if ( $cross_sells ) : 
        echo '<div class="cross-sells"><h2>';
        _e( 'You may be interested in&hellip;', 'woocommerce' );
        echo '</h2>';
            foreach ( $cross_sells as $cross_sell ) :
                $post_object = get_post( $cross_sell->get_id() );
                setup_postdata( $GLOBALS['post'] =& $post_object );
                wc_get_template_part( 'content', 'product' ); 
        echo '</div>';
    else : {
        echo 'No cross sells to display';
add_action( 'woocommerce_after_cart_table', 'show_cross_sell', 10 );

But, only the else condition runs and displays “No cross sells to display”. So maybe it lost scope on the $cross_sells object.

Is there any hope of my being able to achieve this?

Read more here: Combined WooCommerce Checkout/Cart page and adding cross-sell

Leave a Reply

Your email address will not be published. Required fields are marked *