简体   繁体   English

如何将CSS添加到PHP脚本?

[英]How can I add CSS to a PHP script?

This is the script on which I'd like to add some CSS : 这是我要添加一些CSS的脚本:

// Download URLs
        if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
            $download_files = $order->get_item_downloads( $item );
            $i              = 0;
            foreach ( $download_files as $download_id => $file ) {
                $i++;
                if ( count( $download_files ) > 1 ) {
                    $prefix = sprintf( __( 'Download %d', 'woocommerce' ), $i );
                } elseif ( $i == 1 ) {
                    $prefix = __( 'Download', 'woocommerce' );
                }
                echo "\n" . $prefix . '(' . esc_html( $file['name'] ) . '): ' . esc_url( $file['download_url'] );
            }
        }
        // allow other plugins to add additional product information here
        do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order );
    }

It is part of a Woocommerce email (completed order). 它是Woocommerce电子邮件(完整订单)的一部分。 I'd like to add some CSS there, how can I do this ? 我想在那里添加一些CSS,该怎么做?

According to Woocommerce documentation, a more powerful (and advanced) way to customize order emails is to override an email template file. 根据Woocommerce文档,一种更强大(更高级)的自定义订单电子邮件的方法是覆盖电子邮件模板文件。 WooCommerce uses a convenient templating system that allows you to customize parts of your site (or emails) by copying the relevant template file into your theme, and modifying the code there. WooCommerce使用便利的模板系统,通过将相关模板文件复制到主题中并在其中修改代码,可以自定义网站(或电子邮件)的一部分。 Each of the email types has a template file for its content 每种电子邮件类型都有其内容的模板文件

Can you check woocommerce documentation here 您可以在这里查看woocommerce文档吗

Please check below code 请检查下面的代码

First Solution 第一个解决方案

<?php
  $css = file_get_contents('CSS/main.css');
  echo $css;
?>

Second Solution 第二解决方案

<style>
  <?php include 'CSS/styles.css'; ?>
</style>

Third Solution 第三解决方案

<link rel="stylesheet" href="CSS/styles.css" type="text/css">

It's very simple. 非常简单 Just do like this: 就是这样:

<?php if($page=='page'): ?> 
  <style>.container{width:100%}</style>
<?php else: ?>
    ...
<?php endif;?>

If you want to add something on the download do it like this: 如果要在下载中添加一些内容,请按以下步骤进行:

$prefix = sprintf( __( '<strong>Download</strong> <span style="padding-top:10px;>"%d</span>', 'woocommerce' ), $i );

Otherwise, as the others said here, file_get_contents(foo.css) or <? echo "<style>{something;}</style>"; 否则,就像其他人在这里所说的那样, file_get_contents(foo.css)<? echo "<style>{something;}</style>"; <? echo "<style>{something;}</style>";

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

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