title: Wordpress Critical Error Due to Plugin Conflict with my Functions.php
body: <p>I just installed a new Plugin (WooCommerce SEO plugin) which causes a critical error on my web site, causing me to not be able to enter the Products area of my Wordpress/WooCommerce Dashboard on the backend. (Shows a Critical Error has occured and the page is white with that warning text)</p>
  <p>The website actually runs fine, but I cannot edit or view any Products in the Products Dashboard when this WooCommerce SEO Plugin activated.</p>
  <p>I have narrowed down the conflict, but don't know how to fix it. Yes, I could disable the plugin, but I need this, and the conflict is based on a custom code I added to my Child theme's Functions.php file. This shows an alert when the stock is low (with only one left):</p>
  <pre><code>
  // WooCommerce Stock message 
  add_filter( 'woocommerce_get_availability', 'mw_get_availability', 1, 2 ); 
  
  function mw_get_availability( $availability, $_product ) { 
  
  //change text &quot;In Stock' to 'SPECIAL ORDER' 
  global $product; 
  if ( $_product-&gt;is_in_stock() &amp;&amp; $product-&gt;get_stock_quantity() &lt; 2 ) $availability['availability'] = $product-&gt;get_stock_quantity().' '.__('IN STOCK &lt;p style=\&quot;border:3px; border-style:solid; font-weight: bold; border-color:#FF0000; padding: 15px;\&quot;&gt;HURRY! LAST ONE AVAILABLE!&lt;/p&gt;', 'woocommerce'); 
  
  //change text &quot;Out of Stock' to 'SOLD OUT' 
  if ( !$_product-&gt;is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce'); 
  
  return $availability; 
  
  } 
  
  </code></pre>
  <p>This code works beautifully for my site. However, when used with the WooCommerce SEO plugin, I get the following error:</p>
  <pre><code>Error Details
  =============
  An error of type E_ERROR was caused in line 88 of the file /home/site/public_html/website/wp-content/themes/photome-child/functions.php. Error message: Uncaught Error: Call to a member function get_stock_quantity() on null in /home/site/public_html/website/wp-content/themes/photome-child/functions.php:88
  Stack trace:
  #0 /home/site/public_html/website/wp-includes/class-wp-hook.php(303): mw_get_availability(Array, Object(WC_Product_Simple))
  #1 /home/site/public_html/website/wp-includes/plugin.php(189): WP_Hook-&gt;apply_filters(Array, Array)
  #2 /home/site/public_html/website/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(2061): apply_filters('woocommerce_get...', Array, Object(WC_Product_Simple))
  #3 /home/site/public_html/website/wp-content/plugins/wpseo-woocommerce/classes/woocommerce-seo.php(1280): WC_Product-&gt;get_availability()
  #4 /home/site/public_html/website/wp-content/plugins/wpseo-woocommerce/classes/woocommerce-seo.php(916): Yoast_WooCommerce_SEO-&gt;localize_woo_script()
  #5 /home/site/public_html/website/wp-includes/class-wp-hook.php(303): Yoast_WooCommerce_SEO-&gt;enqueue_scripts('edit.php')
  #6 /home/the
  </code></pre>
  <p>The error starts on the line:</p>
  <pre><code>if ( $_product-&gt;is_in_stock() &amp;&amp; $product-&gt;get_stock_quantity() &lt; 2 ) $availability['availability'] = $product-&gt;get_stock_quantity().' '.__('IN STOCK &lt;p style=\&quot;border:3px; border-style:solid; font-weight: bold; border-color:#FF0000; padding: 15px;\&quot;&gt;HURRY! LAST ONE AVAILABLE!&lt;/p&gt;', 'woocommerce');  
  </code></pre>
  <p>I have googled this and found that it is because possibly WooCommerce SEO uses an array and this causes an error?</p>
  <p>I would really like to use WooCommerce SEO <em>and</em> be able to use my simple custom code that works great.</p>
  <p>Hopefully, there's a simple fix to my custom code that someone can see so I can update it so it will not cause this error.</p>
  <p>I'm stumped.</p>
  <p>Any help is greatly appreciated, thanks.</p>