/*
 Theme Name:   Bricks Child Theme
 Theme URI:    https://bricksbuilder.io/
 Description:  Use this child theme to extend Bricks.
 Author:       Bricks
 Author URI:   https://bricksbuilder.io/
 Template:     bricks
 Version:      1.1
 Text Domain:  bricks
*/

add_action('template_redirect', function () {

    // On ne fait ça que sur la page panier
    if ( ! function_exists('is_cart') || ! is_cart() ) {
        return;
    }

    // On ne redirige que si le paramètre est présent (pour ne pas casser le panier normal)
    if ( ! isset($_GET['go']) || $_GET['go'] !== 'checkout' ) {
        return;
    }

    if ( ! function_exists('WC') || ! WC()->cart ) {
        return;
    }

    // Une fois le panier réellement rempli, on envoie vers checkout
    if ( ! WC()->cart->is_empty() ) {
        wp_safe_redirect( wc_get_checkout_url() );
        exit;
    }
});