woocommerce_cross_sell_display( int $limit = 2, int $columns = 2, string $orderby = 'rand', string $order = 'desc' )

Output the cart cross-sells.


Description Description


Parameters Parameters

$limit

(Optional) (default: 2).

Default value: 2

$columns

(Optional) (default: 2).

Default value: 2

$orderby

(Optional) (default: 'rand').

Default value: 'rand'

$order

(Optional) (default: 'desc').

Default value: 'desc'


Top ↑

Source Source

File: includes/wc-template-functions.php

2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
function woocommerce_cross_sell_display( $limit = 2, $columns = 2, $orderby = 'rand', $order = 'desc' ) {
    if ( is_checkout() ) {
        return;
    }
    // Get visible cross sells then sort them at random.
    $cross_sells = array_filter( array_map( 'wc_get_product', WC()->cart->get_cross_sells() ), 'wc_products_array_filter_visible' );
 
    wc_set_loop_prop( 'name', 'cross-sells' );
    wc_set_loop_prop( 'columns', apply_filters( 'woocommerce_cross_sells_columns', $columns ) );
 
    // Handle orderby and limit results.
    $orderby     = apply_filters( 'woocommerce_cross_sells_orderby', $orderby );
    $order       = apply_filters( 'woocommerce_cross_sells_order', $order );
    $cross_sells = wc_products_array_orderby( $cross_sells, $orderby, $order );
    $limit       = apply_filters( 'woocommerce_cross_sells_total', $limit );
    $cross_sells = $limit > 0 ? array_slice( $cross_sells, 0, $limit ) : $cross_sells;
 
    wc_get_template(
        'cart/cross-sells.php',
        array(
            'cross_sells'    => $cross_sells,
 
            // Not used now, but used in previous version of up-sells.php.
            'posts_per_page' => $limit,
            'orderby'        => $orderby,
            'columns'        => $columns,
        )
    );
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.