Using $this from child class inside shortcode function

Your issue is in the callable object you add:

array( __CLASS__, "build_shortcode")

This translates to:

array( "WC_Product_Categories", "build_shortcode")

Which is equivalent to:

WC_Product_Categories::build_shortcode();

But build_shortcode is not a static function/method, and static functions/methods do not have a $this object, because there is no object associated.

What you actually want is:

array( $this, 'build_shortcode' )

Which translates to:

$this->build_shortcode();

Which is what you expected.

Final Notes

  • A lot of people use &$this instead. This is wrong. It’s a holdover from PHP4, and doesn’t do the same thing in very subtle ways. When you see this, remove the & reference
  • Do not use the extract function. It takes the contents of an array and spills it out into the current namespace. Anything could be in there. It also encourages bad code, hides were variables come from, and cripples IDE code intel and automated tooling. Avoid it at all costs.