0

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.

2

0

Your Answer

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