title: Overriding a theme function from plugin in WordPress
body: <p>Is it possible to override a function in a theme, from a plugin? I've been struggling to find an example of how I would achieve the above.</p>
  
  <p>If anyone could shed any light it would be really helpful.</p>
  
  <p>edit: Adding some code</p>
  
  <p>So this is my function which allows the cart in woocommerce to update using ajax:</p>
  
  <pre><code>add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cartplus_fragment', '1');
  
  function woocommerce_header_add_to_cartplus_fragment( $fragments ) {
      global $woocommerce;
      $basket_icon = esc_attr($instance['basket_icon']);
  
      ob_start();
  
      ?&gt;
      &lt;a class="cartplus-contents" href="&lt;?php echo $woocommerce-&gt;cart-&gt;get_cart_url(); ?&gt;" onclick="javscript: return false;" title="&lt;?php _e('View your shopping cart', 'woothemes'); ?&gt;"&gt;&lt;?php echo sprintf(_n('%d item', '%d items', $woocommerce-&gt;cart-&gt;cart_contents_count, 'woothemes'), $woocommerce-&gt;cart-&gt;cart_contents_count);?&gt; - &lt;?php echo $woocommerce-&gt;cart-&gt;get_cart_total(); ?&gt;&lt;/a&gt;
      &lt;?php
  
      $fragments['a.cartplus-contents'] = ob_get_clean();
  
      return $fragments;
  
  }
  </code></pre>
  
  <p>However, some themes also have a similar function built in - in these themes my code stops working which seems strange as I use the above code twice in my plugin (one is a variation of the above) and they work fine together. This is the code built in to the theme:</p>
  
  <pre><code>add_filter('add_to_cart_fragments', 'woocommerce_cart_link');
  
  function woocommerce_cart_link() {
      global $woocommerce;
  
      ob_start();
  
      ?&gt;
      &lt;a href="&lt;?php echo $woocommerce-&gt;cart-&gt;get_cart_url(); ?&gt;" title="&lt;?php echo sprintf(_n('%d item', '%d items', $woocommerce-&gt;cart-&gt;cart_contents_count, 'woothemes'), $woocommerce-&gt;cart-&gt;cart_contents_count);?&gt; &lt;?php _e('in your shopping cart', 'woothemes'); ?&gt;" class="cart-button "&gt;
      &lt;span class="label"&gt;&lt;?php _e('My Basket:', 'woothemes'); ?&gt;&lt;/span&gt;
      &lt;?php echo $woocommerce-&gt;cart-&gt;get_cart_total();  ?&gt;
      &lt;span class="items"&gt;&lt;?php echo sprintf(_n('%d item', '%d items', $woocommerce-&gt;cart-&gt;cart_contents_count, 'woothemes'), $woocommerce-&gt;cart-&gt;cart_contents_count); ?&gt;&lt;/span&gt;
      &lt;/a&gt;
      &lt;?php
  
      $fragments['a.cart-button'] = ob_get_clean();
  
      return $fragments;
  
  }
  </code></pre>