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 7
rgranlundAsked:
Who is Participating?
 
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
 
rgranlundAuthor Commented:
Thanks Steve.  I appreciate the insight and assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.