0

I have a syntax error in my php code and just cannot figure out how should I fix it. I've been trying for ages and narrowed down the faulty code to the following :

<?php 
global $post;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );

if ( ! class_exists( 'Tax_Meta_Boxes' ) ) :

class Tax_Meta_Boxes {

    public function __construct() {

        add_action( 'save_post', array( $this, 'tax_meta_data' ) );
    }
}
?>

I ran the code through the PHP checker, the error seems to be with the last line and ?>. I tried fiddling around with it, remove it, but error still there.

The error is caused by the function :

if ( ! class_exists( 'Tax_Meta_Boxes' ) ) :

class Tax_Meta_Boxes {

    public function __construct() {

        add_action( 'save_post', array( $this, 'tax_meta_data' ) );
    }
}

If I remove the function, my error is gone, but what is wrong in the code of this function, how can I fix it ?

1 Answer 1

4

You have missed endif; for your if()

<?php 
global $post;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );

if ( ! class_exists( 'Tax_Meta_Boxes' ) ) :

class Tax_Meta_Boxes {

    public function __construct() {

        add_action( 'save_post', array( $this, 'tax_meta_data' ) );
    }
}

endif;// this line

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.