<?php 
    
$add_to_cart = do_shortcode('[add_to_cart_url id="' . $post->ID . '"]'); 
$checkout_url = wc_get_checkout_url($post->ID);

// Check if item is in cart	
global $woocommerce;
$product_id = $product->id;

foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    $_product = $values['data'];
    
    if ( $_product->id == $product_id ) {
        $found = true;
    }
}

if ( ! $found ) { ?>

<a href="<?=$add_to_cart;?>" class="single_add_to_cart_button">Buy Now</a>

<?php } else { ?>

<a href="<?=$checkout_url;?>" class="single_add_to_cart_button">Proceed to Checkout</a>

<?php } ?>