title: Converting procedural PHP to OOP
body: <p>I am very new to OOP but I think I have the basics down and I am trying to learn by doing. So I decided to convert my simple wordpress plugin from procedural code to a class method but I keep getting fatal errors.</p>
  
  <p>here is my procedural code that works:</p>
  
  <pre><code>&lt;?php
  if ( ! defined( 'ABSPATH' ) ) { 
      exit; // Exit if accessed directly
  }
  
  //Check if WooCommerce is active
  if ( is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) {
  
  //Load plugin styles
  function woa_wqfsp_stylesheet() 
  {
      wp_enqueue_style( 'wqfspCSS', plugin_dir_path( 'css/style.css', __FILE__ ) );
  }
  add_action('wp_enqueue_scripts', 'woa_wqfsp_stylesheet');
  
  //add quantity fields
  add_filter( 'woocommerce_loop_add_to_cart_link', 'woa_add_quantity_fields', 10, 2 );
  function woa_add_quantity_fields( $html, $product ) {
      if ( $product &amp;&amp; $product-&gt;is_type( 'simple' ) &amp;&amp; $product-&gt;is_purchasable() &amp;&amp; $product-&gt;is_in_stock() &amp;&amp; ! $product-&gt;is_sold_individually() ) {
          $html = '&lt;form action="' . esc_url( $product-&gt;add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data"&gt;';
          $html .= woocommerce_quantity_input( array(), $product, false );
          $html .= '&lt;button type="submit" class="button alt"&gt;' . esc_html( $product-&gt;add_to_cart_text() ) . '&lt;/button&gt;';
          $html .= '&lt;/form&gt;';
      }
      return $html;
  }
  
  }//main end
  ?&gt;
  </code></pre>
  
  <p>This is my OOP code but I keep getting errors:</p>
  
  <pre><code>&lt;?php
  
  if ( ! defined( 'ABSPATH' ) ) { 
      exit; // Exit if accessed directly
  }
  
  function woa_wqfsp() {
      return woa_wqfsp();
  } // End woa_wqfsp()
  
  woa_wqfsp();
  
  class woa_wqfsp {
  
      private static $_instance = null;
      private $html;
      private $product;
  
      public function __construct() {
  
          add_action( 'init', array( $this, 'setup' ) );
      }
  
      public static function instance() {
          if ( is_null( self::$_instance ) )
              self::$_instance = new self();
          return self::$_instance;
      }
  
  //Load plugin styles
  function woa_wqfsp_stylesheet() 
  {
      wp_enqueue_style( 'wqfspCSS', plugin_dir_path( 'css/style.css', __FILE__ ) );
  }
  
  
  
  function woa_add_quantity_fields( $html, $product ) {
      if ( $this-&gt;$product &amp;&amp; $this-&gt;$product-&gt;is_type( 'simple' ) &amp;&amp; $this-&gt;$product-&gt;is_purchasable() &amp;&amp; $this-&gt;$product-&gt;is_in_stock() &amp;&amp; ! $this-&gt;$product-&gt;is_sold_individually() ) {
          $html = '&lt;form action="' . esc_url( $this-&gt;$product-&gt;add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data"&gt;';
          $html .= woocommerce_quantity_input( array(), $this-&gt;$product, false );
          $html .= '&lt;button type="submit" class="button alt"&gt;' . esc_html( $this-&gt;$product-&gt;add_to_cart_text() ) . '&lt;/button&gt;';
          $html .= '&lt;/form&gt;';
      }
      return $html;
  }
  
  function woa_wqfsp_run() {
  //Check if WooCommerce is active
  if ( is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) {
  //add style for quantity field
  add_action('wp_enqueue_scripts', $this-&gt;woa_wqfsp_stylesheet);
  //add quantity fields
  add_filter( 'woocommerce_loop_add_to_cart_link', $this-&gt;woa_add_quantity_fields, 10, 2 );
  
  }
  }
  
  }//class end
  ?&gt;
  </code></pre>
  
  <p>could someone please point out what Im doing wrong? I think it is around this section: function woa_add_quantity_fields( $html, $product )</p>
  
  <p>$html is just a null var and product is a global var by woocommerce</p>
  
  <p>THanks in advance</p>