User Direct Write in URL (Checkout) then Product Automatically Add to the Cart

 <?php 
/* Check if product is available or not */
add_action( 'template_redirect', 'check_if_product_is_available_in_cart', 1 );
function check_if_product_is_available_in_cart(){
if( is_checkout() ){

$product_id = 2622; 
$found = false;

if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->get_id() == $product_id )
$found = true;
}
if ( ! $found )
WC()->cart->add_to_cart( $product_id );

else {
WC()->cart->add_to_cart( $product_id );
}
}
}