Get custom email placeholder value on Woocommerce custom email content





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I've created my own email class in WooCommerce. Because I need a custom parameter in my email content, I've added a placeholder with this custom parameter to the wc email trigger function:



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}




After his I've did this in the content PHP file:



<?php printf( __( get_option( 'wc_custom_email_info' ) ), '{full_name}' ); ?>


In the option I've wrote %s so that I can add the full name into to content. But sadly I'm getting the name of the placeholder and not the content:




Blaaaaaaa {full_name} blaaaa




But I need this here:




Blaaaaaaa Joe Martin blaaaa




Update


The name here is not the customer name from the order. This is a name which I pass through a do_action which I trigger from a button. So when someone on my page clicks this button, I'm fetching his user id and get the name from the user who clicked the button. This is the custom email trigger I use:



$user      = get_userdata( get_current_user_id() );
$firstname = $user->user_firstname;
$lastname = $user->last_name;

//Trigger email sending
do_action( 'trigger_email', $order_id, $firstname, $lastname );


Then I do this in the email class:



//Trigger for this email.
add_action( 'trigger_email', array( $this, 'trigger' ), 10, 10 );


After this you can go back to the top trigger function.










share|improve this question

























  • Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

    – Mr. Jo
    Nov 22 '18 at 23:47











  • @LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

    – Mr. Jo
    Nov 22 '18 at 23:49











  • <?php echo $this->placeholders['{full_name}']; ?>

    – Mr. Jo
    Nov 22 '18 at 23:49













  • Let us continue this discussion in chat.

    – Mr. Jo
    Nov 22 '18 at 23:50


















2















I've created my own email class in WooCommerce. Because I need a custom parameter in my email content, I've added a placeholder with this custom parameter to the wc email trigger function:



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}




After his I've did this in the content PHP file:



<?php printf( __( get_option( 'wc_custom_email_info' ) ), '{full_name}' ); ?>


In the option I've wrote %s so that I can add the full name into to content. But sadly I'm getting the name of the placeholder and not the content:




Blaaaaaaa {full_name} blaaaa




But I need this here:




Blaaaaaaa Joe Martin blaaaa




Update


The name here is not the customer name from the order. This is a name which I pass through a do_action which I trigger from a button. So when someone on my page clicks this button, I'm fetching his user id and get the name from the user who clicked the button. This is the custom email trigger I use:



$user      = get_userdata( get_current_user_id() );
$firstname = $user->user_firstname;
$lastname = $user->last_name;

//Trigger email sending
do_action( 'trigger_email', $order_id, $firstname, $lastname );


Then I do this in the email class:



//Trigger for this email.
add_action( 'trigger_email', array( $this, 'trigger' ), 10, 10 );


After this you can go back to the top trigger function.










share|improve this question

























  • Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

    – Mr. Jo
    Nov 22 '18 at 23:47











  • @LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

    – Mr. Jo
    Nov 22 '18 at 23:49











  • <?php echo $this->placeholders['{full_name}']; ?>

    – Mr. Jo
    Nov 22 '18 at 23:49













  • Let us continue this discussion in chat.

    – Mr. Jo
    Nov 22 '18 at 23:50














2












2








2








I've created my own email class in WooCommerce. Because I need a custom parameter in my email content, I've added a placeholder with this custom parameter to the wc email trigger function:



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}




After his I've did this in the content PHP file:



<?php printf( __( get_option( 'wc_custom_email_info' ) ), '{full_name}' ); ?>


In the option I've wrote %s so that I can add the full name into to content. But sadly I'm getting the name of the placeholder and not the content:




Blaaaaaaa {full_name} blaaaa




But I need this here:




Blaaaaaaa Joe Martin blaaaa




Update


The name here is not the customer name from the order. This is a name which I pass through a do_action which I trigger from a button. So when someone on my page clicks this button, I'm fetching his user id and get the name from the user who clicked the button. This is the custom email trigger I use:



$user      = get_userdata( get_current_user_id() );
$firstname = $user->user_firstname;
$lastname = $user->last_name;

//Trigger email sending
do_action( 'trigger_email', $order_id, $firstname, $lastname );


Then I do this in the email class:



//Trigger for this email.
add_action( 'trigger_email', array( $this, 'trigger' ), 10, 10 );


After this you can go back to the top trigger function.










share|improve this question
















I've created my own email class in WooCommerce. Because I need a custom parameter in my email content, I've added a placeholder with this custom parameter to the wc email trigger function:



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}




After his I've did this in the content PHP file:



<?php printf( __( get_option( 'wc_custom_email_info' ) ), '{full_name}' ); ?>


In the option I've wrote %s so that I can add the full name into to content. But sadly I'm getting the name of the placeholder and not the content:




Blaaaaaaa {full_name} blaaaa




But I need this here:




Blaaaaaaa Joe Martin blaaaa




Update


The name here is not the customer name from the order. This is a name which I pass through a do_action which I trigger from a button. So when someone on my page clicks this button, I'm fetching his user id and get the name from the user who clicked the button. This is the custom email trigger I use:



$user      = get_userdata( get_current_user_id() );
$firstname = $user->user_firstname;
$lastname = $user->last_name;

//Trigger email sending
do_action( 'trigger_email', $order_id, $firstname, $lastname );


Then I do this in the email class:



//Trigger for this email.
add_action( 'trigger_email', array( $this, 'trigger' ), 10, 10 );


After this you can go back to the top trigger function.







php wordpress woocommerce placeholder email-notifications






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 1:14









LoicTheAztec

98.2k1472114




98.2k1472114










asked Nov 22 '18 at 23:06









Mr. JoMr. Jo

992319




992319













  • Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

    – Mr. Jo
    Nov 22 '18 at 23:47











  • @LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

    – Mr. Jo
    Nov 22 '18 at 23:49











  • <?php echo $this->placeholders['{full_name}']; ?>

    – Mr. Jo
    Nov 22 '18 at 23:49













  • Let us continue this discussion in chat.

    – Mr. Jo
    Nov 22 '18 at 23:50



















  • Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

    – Mr. Jo
    Nov 22 '18 at 23:47











  • @LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

    – Mr. Jo
    Nov 22 '18 at 23:49











  • <?php echo $this->placeholders['{full_name}']; ?>

    – Mr. Jo
    Nov 22 '18 at 23:49













  • Let us continue this discussion in chat.

    – Mr. Jo
    Nov 22 '18 at 23:50

















Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

– Mr. Jo
Nov 22 '18 at 23:47





Because I've added there my custom text which defines the content. To get the name in the content I'm passing it as a parameter

– Mr. Jo
Nov 22 '18 at 23:47













@LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

– Mr. Jo
Nov 22 '18 at 23:49





@LoicTheAztec PHP Fatal error: Uncaught Error: Using $this when not in object context

– Mr. Jo
Nov 22 '18 at 23:49













<?php echo $this->placeholders['{full_name}']; ?>

– Mr. Jo
Nov 22 '18 at 23:49







<?php echo $this->placeholders['{full_name}']; ?>

– Mr. Jo
Nov 22 '18 at 23:49















Let us continue this discussion in chat.

– Mr. Jo
Nov 22 '18 at 23:50





Let us continue this discussion in chat.

– Mr. Jo
Nov 22 '18 at 23:50












1 Answer
1






active

oldest

votes


















1














Updated




Placeholders in email are only for the email subject in Woocommerce




So what you are trying to do can't work this way.



Instead you will need to make a little change in your trigger() function and adding another method in your class:



/**
* Trigger the sending of this email.
*/
public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->formatted_name = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;

if ( 'plain' === $this->get_email_type() ) {
$email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) );
} else {
$email_content = str_replace( '{full_name}', $this->formatted_name, $this->get_content_html() );
}

return wordwrap( $email_content, 70 );
}


This time your placeholder should be replaced with your dynamic $firstname . ' ' . $lastname; when using in your template (content):



<?php printf( get_option( 'wc_custom_email_info' ), '{full_name}' ); ?>




Original answer



Try the following instead that use WC_Order method get_formatted_billing_full_name():



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $this->object->get_formatted_billing_full_name();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}


It should works. Before on your code $firstname and $lastname were not defined;






share|improve this answer


























  • Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

    – Mr. Jo
    Nov 22 '18 at 23:33











  • I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

    – Mr. Jo
    Nov 22 '18 at 23:39













  • This works great! Thank you sir.

    – Mr. Jo
    Nov 23 '18 at 0:50












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438921%2fget-custom-email-placeholder-value-on-woocommerce-custom-email-content%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Updated




Placeholders in email are only for the email subject in Woocommerce




So what you are trying to do can't work this way.



Instead you will need to make a little change in your trigger() function and adding another method in your class:



/**
* Trigger the sending of this email.
*/
public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->formatted_name = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;

if ( 'plain' === $this->get_email_type() ) {
$email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) );
} else {
$email_content = str_replace( '{full_name}', $this->formatted_name, $this->get_content_html() );
}

return wordwrap( $email_content, 70 );
}


This time your placeholder should be replaced with your dynamic $firstname . ' ' . $lastname; when using in your template (content):



<?php printf( get_option( 'wc_custom_email_info' ), '{full_name}' ); ?>




Original answer



Try the following instead that use WC_Order method get_formatted_billing_full_name():



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $this->object->get_formatted_billing_full_name();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}


It should works. Before on your code $firstname and $lastname were not defined;






share|improve this answer


























  • Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

    – Mr. Jo
    Nov 22 '18 at 23:33











  • I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

    – Mr. Jo
    Nov 22 '18 at 23:39













  • This works great! Thank you sir.

    – Mr. Jo
    Nov 23 '18 at 0:50
















1














Updated




Placeholders in email are only for the email subject in Woocommerce




So what you are trying to do can't work this way.



Instead you will need to make a little change in your trigger() function and adding another method in your class:



/**
* Trigger the sending of this email.
*/
public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->formatted_name = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;

if ( 'plain' === $this->get_email_type() ) {
$email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) );
} else {
$email_content = str_replace( '{full_name}', $this->formatted_name, $this->get_content_html() );
}

return wordwrap( $email_content, 70 );
}


This time your placeholder should be replaced with your dynamic $firstname . ' ' . $lastname; when using in your template (content):



<?php printf( get_option( 'wc_custom_email_info' ), '{full_name}' ); ?>




Original answer



Try the following instead that use WC_Order method get_formatted_billing_full_name():



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $this->object->get_formatted_billing_full_name();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}


It should works. Before on your code $firstname and $lastname were not defined;






share|improve this answer


























  • Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

    – Mr. Jo
    Nov 22 '18 at 23:33











  • I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

    – Mr. Jo
    Nov 22 '18 at 23:39













  • This works great! Thank you sir.

    – Mr. Jo
    Nov 23 '18 at 0:50














1












1








1







Updated




Placeholders in email are only for the email subject in Woocommerce




So what you are trying to do can't work this way.



Instead you will need to make a little change in your trigger() function and adding another method in your class:



/**
* Trigger the sending of this email.
*/
public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->formatted_name = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;

if ( 'plain' === $this->get_email_type() ) {
$email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) );
} else {
$email_content = str_replace( '{full_name}', $this->formatted_name, $this->get_content_html() );
}

return wordwrap( $email_content, 70 );
}


This time your placeholder should be replaced with your dynamic $firstname . ' ' . $lastname; when using in your template (content):



<?php printf( get_option( 'wc_custom_email_info' ), '{full_name}' ); ?>




Original answer



Try the following instead that use WC_Order method get_formatted_billing_full_name():



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $this->object->get_formatted_billing_full_name();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}


It should works. Before on your code $firstname and $lastname were not defined;






share|improve this answer















Updated




Placeholders in email are only for the email subject in Woocommerce




So what you are trying to do can't work this way.



Instead you will need to make a little change in your trigger() function and adding another method in your class:



/**
* Trigger the sending of this email.
*/
public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->formatted_name = $firstname . ' ' . $lastname;
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;

if ( 'plain' === $this->get_email_type() ) {
$email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) );
} else {
$email_content = str_replace( '{full_name}', $this->formatted_name, $this->get_content_html() );
}

return wordwrap( $email_content, 70 );
}


This time your placeholder should be replaced with your dynamic $firstname . ' ' . $lastname; when using in your template (content):



<?php printf( get_option( 'wc_custom_email_info' ), '{full_name}' ); ?>




Original answer



Try the following instead that use WC_Order method get_formatted_billing_full_name():



public function trigger( $order_id, $firstname, $lastname, $order = false ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}

if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{full_name}'] = $this->object->get_formatted_billing_full_name();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}


It should works. Before on your code $firstname and $lastname were not defined;







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 1:10

























answered Nov 22 '18 at 23:29









LoicTheAztecLoicTheAztec

98.2k1472114




98.2k1472114













  • Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

    – Mr. Jo
    Nov 22 '18 at 23:33











  • I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

    – Mr. Jo
    Nov 22 '18 at 23:39













  • This works great! Thank you sir.

    – Mr. Jo
    Nov 23 '18 at 0:50



















  • Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

    – Mr. Jo
    Nov 22 '18 at 23:33











  • I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

    – Mr. Jo
    Nov 22 '18 at 23:39













  • This works great! Thank you sir.

    – Mr. Jo
    Nov 23 '18 at 0:50

















Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

– Mr. Jo
Nov 22 '18 at 23:33





Thank you for your answer but I don't want to display the customer name. This is the name from a user which triggers the email sending from a button on my page. Take a look at my question, I'll post an update there. Sorry for beein not exactly.

– Mr. Jo
Nov 22 '18 at 23:33













I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

– Mr. Jo
Nov 22 '18 at 23:39







I've added some code. The $order object variable is in it but the name I need comes not from this variable. If it would the solution would be simple like you described in your answer.

– Mr. Jo
Nov 22 '18 at 23:39















This works great! Thank you sir.

– Mr. Jo
Nov 23 '18 at 0:50





This works great! Thank you sir.

– Mr. Jo
Nov 23 '18 at 0:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438921%2fget-custom-email-placeholder-value-on-woocommerce-custom-email-content%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents