Wordpress override a Class Method

I want to override a Class Method in Wordpress.  Here is the class and Method
if( !class_exists( 'Woo_Os_Public' ) ) { // If class not exist
	class Woo_Os_Public {

public function add_hooks() {
			
			// checkout process
			add_action( 'woocommerce_checkout_process', array( $this, 'woo_os_checkout_field_process' ) );

}
}
}

Open in new window


I want to override add_hooks

Here is what I have:
if (!class_exists('Woo_Os_Public')) { // If class not exist

    class Wizard_class extends Woo_Os_Public {

        public function add_hooks() {
// add custom fields to checkout page
            add_action('woocommerce_checkout_after_customer_details', array($this, 'woo_os_checkout_fields'));
        }

    }

}
$wizard_public = Woo_Os_Public();
$wizard_public->wizard = new Wizard_class;

Open in new window


I receive an error: Fatal error: Class 'Woo_Os_Public' not found in wp-content/plugins/nda/nda-plugin.php on line 31
Line 31 is: class Wizard_class extends Woo_Os_Public {
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Your logic is saying, "If this class doesn't exist, here's a class definition which extends it."  The if() is supposed to be a safeguard against redeclaration.  Change it to reflect that:
if (!class_exists('Wizard_class')) {

Open in new window


Also, since you're receiving that error, the base class is not defined when that code runs.  Make sure you include it, or have the autoloader load it, by the time this executes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
Thanks Steve.  I appreciate the insight and assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.