简体   繁体   English

如何在WooCommerce电子邮件中设置银行详细信息的样式?

[英]How to stylize bank details in WooCommerce email?

I can see this part outputted by the following code: 我可以看到以下代码输出的这一部分:

<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>

Action woocommerce_email_before_order_table is in the file woocommerce/includes/gateways/class-wc-gateway-bacs.php 动作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 );

Email instructions is in the same file: 电子邮件说明位于同一文件中:

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

And part I'm interested in: 我感兴趣的部分是:

/**
 * 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>';
        }
    }
}

I want to add some inline styles to h2, h3 and li elements to stylize they in emails. 我想向h2,h3和li元素添加一些内联样式以在电子邮件中对其进行样式化。 How can I do it with filters (or other method to do not lost changes after updating) if this function outputs the result and doesn't return it and doesn't store data in variables? 如果此函数输出结果并且不返回结果并且不将数据存储在变量中,该如何使用过滤器(或其他方法来确保更新后不会丢失更改)呢?

I can see in the emails there are some inline styles in the h2 and h3 but I can't understand where they are from. 我可以在电子邮件中看到h2和h3中有一些内联样式,但我不知道它们的来源。

I will be grateful for any help. 我将不胜感激。

You could try to add some custom styling for all H2 and H3 tags that are used inside the e-mail templates. 您可以尝试为电子邮件模板内使用的所有H2和H3标签添加一些自定义样式。 I've successfully styled the individual H2 and H3 tags by adding inline styling (presumably just like you did), but the BACS details are not covered inside the templates, they are generated by the external function you're referring to. 我已经通过添加内联样式成功地为单独的H2和H3标签设置了样式(大概就像您所做的那样),但是BACS详细信息并未包含在模板内部,它们是由您所引用的外部函数生成的。

To achieve this, open the file email-header.php (after copying it to your custom theme folder) and add the following code right before the closing head tag (): 为此,请打开文件email-header.php(将其复制到自定义主题文件夹之后),并在结束标记()之前添加以下代码:

<style>h2,h3 { font-size: 14px !important; color: #000 !important; }</style>

This will ensure the H2 and H3 tags are styled using a 14px font-size and a #000 color (using the !important rule to override inline styling). 这将确保使用14px字体大小和#000颜色(使用!important规则覆盖内联样式)对H2和H3标签进行样式设置。 Offcours you can modify the styling to your wishes. 当然,您可以根据自己的意愿修改样式。

Although there is a comment about global styling not playing nice with Gmail, the styling seems to applied just fine while reading the e-mail with Gmail. 尽管有人评论说全局样式不能与Gmail配合使用,但是在使用Gmail阅读电子邮件时,该样式似乎可以很好地应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM