Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Add CSS to WooCommerce Emails
<?php
/**
* Plugin Name: WooCommerce Add CSS to Emails
* Plugin URI: https://gist.github.com/BFTrick/01cc414ee56ce93715ec
* Description: Add CSS styles to WooCommerce emails
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
if ( ! class_exists( 'WC_Add_CSS_To_Email' ) ) :
class WC_Add_CSS_To_Email {
protected static $instance = null;
/**
* Initialize the plugin.
*
* @since 1.0
*/
private function __construct() {
if ( class_exists( 'WooCommerce' ) && class_exists( 'WC_Emails' ) ) {
// set subject
add_filter( 'woocommerce_email_styles', array( $this, 'add_styles' ) );
}
}
/**
* Return the CSS for WooCommerce emails
*
* @return string css for emails
* @since 1.0
*/
public function add_styles( $css ) {
$css = $css . "p {color: red}";
return $css;
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
* @since 1.0
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
add_action( 'admin_init', array( 'WC_Add_CSS_To_Email', 'get_instance' ), 0 );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment