add_action( 'template_redirect', 'snippet_add_product_to_cart' ); function snippet_add_product_to_cart() { // select ID $product_id = 21874; //check if product already in cart if ( WC()->cart->get_cart_contents_count() == 0 ) { // if no products in cart, add it WC()->cart->add_to_cart( $product_id ); } }