Skip to content

Commit e07a037

Browse files
committed
New: check if woocommerce is active before getting settings, hook for setting email font
1 parent 10609b6 commit e07a037

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

includes/classes/BrandedEmails.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ public static function get_css_variables() {
150150
return [
151151
'background_color' => apply_filters(
152152
'orbit_branded_emails_background_color',
153-
get_option( 'woocommerce_email_background_color' ) ?:
153+
self::get_woocommerce_setting( 'woocommerce_email_background_color' ) ?:
154154
'#ffffff'
155155
),
156156

157157
'body_background_color' => apply_filters(
158158
'orbit_branded_emails_body_background_color',
159-
get_option( 'woocommerce_email_body_background_color' ) ?:
159+
self::get_woocommerce_setting( 'woocommerce_email_body_background_color' ) ?:
160160
'#ffffff'
161161
),
162162

@@ -170,7 +170,7 @@ public static function get_css_variables() {
170170

171171
'body_text_color' => apply_filters(
172172
'orbit_branded_emails_body_text_color',
173-
get_option( 'woocommerce_email_text_color' ) ?:
173+
self::get_woocommerce_setting( 'woocommerce_email_text_color' ) ?:
174174
self::orbit_branded_emails_resolve_color(
175175
'var(--wp--preset--color--contrast)'
176176
) ?:
@@ -179,7 +179,7 @@ public static function get_css_variables() {
179179

180180
'link_color' => apply_filters(
181181
'orbit_branded_emails_link_color',
182-
get_option( 'woocommerce_email_base_color' ) ?:
182+
self::get_woocommerce_setting( 'woocommerce_email_base_color' ) ?:
183183
self::orbit_branded_emails_resolve_color(
184184
'var(--wp--custom--color--link)'
185185
) ?:
@@ -188,18 +188,22 @@ public static function get_css_variables() {
188188

189189
'footer_text_color' => apply_filters(
190190
'orbit_branded_emails_footer_text_color',
191-
get_option( 'woocommerce_email_footer_text_color' ) ?:
191+
self::get_woocommerce_setting( 'woocommerce_email_footer_text_color' ) ?:
192192
self::orbit_branded_emails_resolve_color(
193193
'var(--wp--preset--color--contrast)'
194194
) ?:
195195
'#3F474d'
196196
),
197197

198-
'font_family' => '"Helvetica Neue", Helvetica, Roboto, Arial, sans-serif',
198+
'font_family' => apply_filters(
199+
'orbit_branded_emails_font_family',
200+
self::get_woocommerce_setting( 'woocommerce_email_font_family' ) ?:
201+
'"Helvetica Neue", Helvetica, Roboto, Arial, sans-serif'
202+
),
199203

200204
'logo_image_width' => apply_filters(
201205
'orbit_branded_emails_logo_image_width',
202-
get_option( 'woocommerce_email_header_image_width' ) ?:
206+
self::get_woocommerce_setting( 'woocommerce_email_header_image_width' ) ?:
203207
120
204208
),
205209
];
@@ -306,4 +310,21 @@ public static function apply_branded_email_colours_to_gf_table_data( $color, $fi
306310

307311
return $data_background_color;
308312
}
313+
314+
/**
315+
* Checks if WooCommerce is active and retrieves a specific setting.
316+
*
317+
* Should only be used for settings that are expected to be set by WooCommerce.
318+
*
319+
* @param string $setting_name The name of the WooCommerce setting to retrieve.
320+
* @return mixed|null The value of the setting, or null if WooCommerce is not active or the setting does not exist.
321+
*/
322+
public static function get_woocommerce_setting( $setting_name ) {
323+
// check if woocommerce is active
324+
if ( ! class_exists( 'WooCommerce' ) ) {
325+
return null;
326+
}
327+
328+
return get_option( $setting_name ) ?: null;
329+
}
309330
}

0 commit comments

Comments
 (0)