Custom block doesn't work correctly when not logged in So I have a custom block module that displays three links, which then when clicked, reload the page and redirect to checkout based on a GET variable.

function innovista_donate_contents() {
  if(isset($_GET['d'])){
    switch ($_GET['d']) {
      case 1:
        $product_id='6';
        break;
      case 2:
        $product_id='8';
        break;
    }       
    commerce_cart_product_add_by_id($product_id, $quantity = 1, $combine = TRUE);
    drupal_goto($path = 'checkout', $options = NULL, $http_response_code = 302);
  }
  else {
    return '&lt;div class="col8wrap donate"&gt;
      &lt;a class="dhover" href="?d=1"&gt;Link 1&lt;/a&gt;
      &lt;a class="dhover" href="?d=2"&gt;Link 2&lt;/a&gt;&lt;/div&gt;';
  }
}


The issue is that if you are not logged in then often the top half of this function that uses the GET var doesn't work. I thought it might be a cache issue so cleared the cache but this hasn't resolved the issue. Any idea what is going on here?
You block is build on the first page request. The else flow is followed. Depending on you settings the page or block is cached. Logged in users don't have cached blocks.

That it worked now and then for anonymous was probably due to your cache clears.

You should create a callback using hook_menu() like

function innovista_donate_menu() {
  return array(
    'innovista/addtocart' =&gt; array(
      'title' =&gt; 'Innovisata add to cart',
      'page callback' =&gt; 'innovista_donate_add_to_cart',
      'access callback' =&gt; TRUE, // Accessible for everybody
      'type' =&gt; MENU_CALLBACK,
    ),
  );
}

function innovista_donate_add_to_cart() {
  if(isset($_GET['d'])){
    switch ($_GET['d']) {
      case 1:
        $product_id='6';
        break;
      case 2:
        $product_id='8';
        break;
    }       
    commerce_cart_product_add_by_id($product_id, 1, TRUE);
    drupal_goto('checkout');
  }
}


Your block can now contain just the links. You can now disabled PHP input filter probably too.

(Note I changed your drupal_goto and removed tabs)