user1717321
user1717321

Reputation: 35

WooCommerce Sensei Email customization

How can a title or text be changed in one template when the filter is shared across templates?

Plugin code (in class-woothemes-sensei-email-learner-graded-quiz.php):

$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template);

My custom code (in functions.php):

add_filter( 'sensei_email_subject', 'my_custom_sensei_email_subject', 'class_woothemes_sensei_email_learner_graded_quiz' );

function my_custom_sensei_email_subject( $subject ) {

    global $woothemes_sensei;

    $subject = sprintf( __( '[%1$s] Your Evaluation has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ));    

    return $subject;
} 

// This changes the title regardless of which template is being used.

Upvotes: 1

Views: 361

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253773

In your function, there is a missing argument, as you can see there is 2 on that filter hook: $subject and $template (which is optional).

So you will need to add this second argument $template in your function. Then in an if statement you can target the correct template only .

Supposing the correct target template slug is: learner_graded_quiz

So the correct code should be:

add_filter( 'sensei_email_subject', 'my_custom_sensei_email_subject', 10, 2 );
function my_custom_sensei_email_subject( $subject, $template ) {
    // Only for your specific template
    if( 'learner-graded-quiz' != $template ) return $subject;

    $subject = sprintf( __( '[%1$s] Your Evaluation has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ));    

    return $subject;
} 

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Not tested as I don't have sensei…

You don't need in your code global $woothemes_sensei; as it's not used.

Upvotes: 2

Related Questions