[英]How to stylize bank details in WooCommerce email?
我可以看到以下代碼輸出的這一部分:
<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
動作woocommerce_email_before_order_table在文件woocommerce / includes / gateways / class-wc-gateway-bacs.php中
// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
電子郵件說明位於同一文件中:
/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @return void
*/
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( ! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status( 'on-hold' ) ) {
if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
}
$this->bank_details( $order->id );
}
}
我感興趣的部分是:
/**
* Get bank details and place into a list format
*/
private function bank_details( $order_id = '' ) {
if ( empty( $this->account_details ) ) {
return;
}
echo '<h2>' . __( 'Our Bank Details', 'woocommerce' ) . '</h2>' . PHP_EOL;
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details );
if ( ! empty( $bacs_accounts ) ) {
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
if ( $bacs_account->account_name || $bacs_account->bank_name ) {
echo '<h3>' . implode( ' - ', array_filter( array( $bacs_account->account_name, $bacs_account->bank_name ) ) ) . '</h3>' . PHP_EOL;
}
echo '<ul class="order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails
$account_fields = apply_filters( 'woocommerce_bacs_account_fields', array(
'account_number'=> array(
'label' => __( 'Account Number', 'woocommerce' ),
'value' => $bacs_account->account_number
),
'sort_code' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
'value' => $bacs_account->sort_code
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $bacs_account->iban
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic
)
), $order_id );
foreach ( $account_fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
echo '<li class="' . esc_attr( $field_key ) . '">' . esc_attr( $field['label'] ) . ': <strong>' . wptexturize( $field['value'] ) . '</strong></li>' . PHP_EOL;
}
}
echo '</ul>';
}
}
}
我想向h2,h3和li元素添加一些內聯樣式以在電子郵件中對其進行樣式化。 如果此函數輸出結果並且不返回結果並且不將數據存儲在變量中,該如何使用過濾器(或其他方法來確保更新后不會丟失更改)呢?
我可以在電子郵件中看到h2和h3中有一些內聯樣式,但我不知道它們的來源。
我將不勝感激。
您可以嘗試為電子郵件模板內使用的所有H2和H3標簽添加一些自定義樣式。 我已經通過添加內聯樣式成功地為單獨的H2和H3標簽設置了樣式(大概就像您所做的那樣),但是BACS詳細信息並未包含在模板內部,它們是由您所引用的外部函數生成的。
為此,請打開文件email-header.php(將其復制到自定義主題文件夾之后),並在結束標記()之前添加以下代碼:
<style>h2,h3 { font-size: 14px !important; color: #000 !important; }</style>
這將確保使用14px字體大小和#000顏色(使用!important規則覆蓋內聯樣式)對H2和H3標簽進行樣式設置。 當然,您可以根據自己的意願修改樣式。
盡管有人評論說全局樣式不能與Gmail配合使用,但是在使用Gmail閱讀電子郵件時,該樣式似乎可以很好地應用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.