WooCommerce::get_instance_of()publicWC 4.4

Gets an instance of a given legacy class. This must not be used to get instances of classes in the src directory.

This method can be useful for unit tests, since objects obtained using this method can be easily mocked by using WC_Unit_Test_Case::register_legacy_proxy_class_mocks.

Method of the class: WooCommerce{}

No Hooks.


Object. The instance of the class.


$WooCommerce = new WooCommerce();
$WooCommerce->get_instance_of( $class_name, ...$args );
$class_name(string) (required)
The name of the class to get an instance for.
...$args(mixed) (required)
Parameters to be passed to the class constructor or to the appropriate internal 'get_instance_of_' method.


Since 4.4 Introduced.

WooCommerce::get_instance_of() code WC 8.3.0

public function get_instance_of( string $class_name, ...$args ) {
	return wc_get_container()->get( LegacyProxy::class )->get_instance_of( $class_name, ...$args );