久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Woocommerce 自定義電子郵件內(nèi)容上獲取自定義電

Get custom email placeholder value on Woocommerce custom email content(在 Woocommerce 自定義電子郵件內(nèi)容上獲取自定義電子郵件占位符值)
本文介紹了在 Woocommerce 自定義電子郵件內(nèi)容上獲取自定義電子郵件占位符值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我在 WooCommerce 中創(chuàng)建了自己的電子郵件類(lèi).因?yàn)槲倚枰谖业碾娮余]件內(nèi)容中使用自定義參數(shù),所以我在 wc 電子郵件觸發(fā)器函數(shù)中添加了一個(gè)帶有此自定義參數(shù)的占位符:

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();
}

<小時(shí)>

在他之后我在內(nèi)容 PHP 文件中做了這個(gè):


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

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

在選項(xiàng)中我寫(xiě)了 %s 以便我可以將全名添加到內(nèi)容中.但遺憾的是,我得到的是占位符的名稱(chēng),而不是內(nèi)容:

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

Blaaaaaaa {full_name} blaaaa

但我需要這個(gè):

Blaaaaaaa 喬·馬丁 blaaaa

Blaaaaaaa Joe Martin blaaaa

更新

此處的名稱(chēng)不是訂單中的客戶名稱(chēng).這是我通過(guò)從按鈕觸發(fā)的 do_action 傳遞的名稱(chēng).因此,當(dāng)我頁(yè)面上的某人單擊此按鈕時(shí),我正在獲取他的用戶 ID 并從單擊該按鈕的用戶那里獲取名稱(chēng).這是我使用的自定義電子郵件觸發(fā)器:

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 );

然后我在電子郵件類(lèi)中這樣做:

Then I do this in the email class:

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

此后您可以返回頂部觸發(fā)功能.

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

推薦答案

更新

電子郵件中的占位符僅用于 Woocommerce 中的電子郵件主題

Placeholders in email are only for the email subject in Woocommerce

所以你嘗試做的事情不能以這種方式工作.

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

相反,您需要對(duì) trigger() 函數(shù)進(jìn)行一些更改,并在類(lèi)中添加另一個(gè)方法:

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 );
}

這次你的占位符應(yīng)該替換為你的動(dòng)態(tài) $firstname .' ' .$lastname; 在您的模板(內(nèi)容)中使用時(shí):

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}' ); ?>

<小時(shí)>

原答案

嘗試以下使用 WC_Order 方法 get_formatted_billing_full_name():

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();
}

它應(yīng)該可以工作.之前在你的代碼 $firstname$lastname 上沒(méi)有定義;

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

這篇關(guān)于在 Woocommerce 自定義電子郵件內(nèi)容上獲取自定義電子郵件占位符值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問(wèn)題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡(jiǎn)單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 日韩成年人视频在线 | 色吧久久| 日韩1区2区 | 国产色99 | 日韩一区二区三区av | 九九热国产精品视频 | 久久久av| 国产在线成人 | 欧美日韩在线免费 | 欧美视频xxx | 中文字幕乱码视频32 | 午夜精品久久久久久久久久久久 | 我要看免费一级毛片 | 日本成年免费网站 | 麻豆91精品91久久久 | 亚洲视频一区在线观看 | 亚洲一区二区三区免费视频 | 欧美久久久网站 | 国产精品不卡 | 人妖一区 | 久久香焦 | 亚洲精品国产第一综合99久久 | 色婷婷综合久久久久中文一区二区 | 欧美精品日韩精品国产精品 | 日韩三级电影一区二区 | 精品免费在线 | 国产精品毛片无码 | 午夜成人免费视频 | 国产欧美视频一区 | 久久久久久久久久久蜜桃 | 免费高清av| 粉嫩国产精品一区二区在线观看 | 国产探花在线精品一区二区 | 伊人免费在线观看 | 国产精品1区2区3区 欧美 中文字幕 | 久在草 | 亚洲三区视频 | 91xxx在线观看 | 97精品超碰一区二区三区 | 在线成人 | 国产精品久久久久久久久久久久冷 |