Plugin function in child theme

Question

I need to customize a message returned from a plugin function using my child theme.
In the plugin:

if ( ! class_exists( 'my_class' ) ) {
    class my_class {
        if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
            add_filter( 'wcm_additional_notification', array( $this, 'wcm_cart_additional_notification' ), 10 );
        }
    }
}

public function wcm_cart_additional_notification( $message ) {
  if ( $this->checked_products ) {
    $message = 'my message';
  }
  return $message;
}

If I add in my functions.php

add_filter( 'wcm_additional_notification', array( $this, 'wcm_cart_additional_notification' ), 10 );
function wcm_cart_additional_notification( $message ) {
if ( $this->checked_products ) {
    $message = 'my new message';
}

or

add_filter( 'wcm_additional_notification',  'wcm_cart_additional_notification' );
function wcm_cart_additional_notification( $message ) {
if ( $this->checked_products ) {
    $message = 'my new message';
}

I get this: “Fatal error: Uncaught Error: Using $this when not in object context”

Hoping someone can point out what I’m doing wrong. Many thanks.

0
, , , , franz877 2 years 2019-10-27T16:42:39-05:00 0 Answers 89 views 0

Leave an answer

Browse
Browse