WC_Shortcode_Cart::output()public staticWC 1.0

Output the cart shortcode.

Method of the class: WC_Shortcode_Cart{}

Return

null. Nothing (null).

Usage

$result = WC_Shortcode_Cart::output( $atts );
$atts(array) (required)
Shortcode attributes.

WC_Shortcode_Cart::output() code WC 9.4.2

public static function output( $atts ) {
	if ( ! apply_filters( 'woocommerce_output_cart_shortcode_content', true ) ) {
		return;
	}

	// Constants.
	wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );

	$atts        = shortcode_atts( array(), $atts, 'woocommerce_cart' );
	$nonce_value = wc_get_var( $_REQUEST['woocommerce-shipping-calculator-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.

	// Update Shipping. Nonce check uses new value and old value (woocommerce-cart). @todo remove in 4.0.
	if ( ! empty( $_POST['calc_shipping'] ) && ( wp_verify_nonce( $nonce_value, 'woocommerce-shipping-calculator' ) || wp_verify_nonce( $nonce_value, 'woocommerce-cart' ) ) ) { // WPCS: input var ok.
		self::calculate_shipping();

		// Also calc totals before we check items so subtotals etc are up to date.
		WC()->cart->calculate_totals();
	}

	// Check cart items are valid.
	do_action( 'woocommerce_check_cart_items' );

	// Calc totals.
	WC()->cart->calculate_totals();

	if ( WC()->cart->is_empty() ) {
		wc_get_template( 'cart/cart-empty.php' );
	} else {
		wc_get_template( 'cart/cart.php' );
	}
}