How to add_filter to a class function within a plugin?

124 views Asked by At

I want to change the output of a permalink that is returned from the plugin function getPermalink().

Here is the plugin file (removed unnecessary lines):

<?php

namespace DgoraWcas;

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
class Product
{
    /**
     * Get product permalink
     *
     * @return string
     */
    public function getPermalink()
    {
        $permalink = $this->wcProduct->get_permalink();
        return apply_filters(
            'dgwt/wcas/product/permalink',
            $permalink,
            $this->productID,
            $this
        );
    }
}

I've tried adding this to my functions file:

add_filter( 'dgwt/wcas/product/permalink', array( __CLASS__, 'testFunction') );
function testFunction() {
    return "test";
}

Just for trial, I was hoping this would return the link as: 'test'.

When I add this the plugin doesn't load content correctly. Am I missing something that happens?

0

There are 0 answers