Reputation: 105
I need to change the color to this part of the code:
'% discount'
(this will show the % of the amount plus the word Discount" but I need to use a particular color for this "% discount"
* Display the discount in payment method title.
*/
public function wpd_payment_method_title($title, $id) {
if (!is_checkout() && !( defined('DOING_AJAX') && DOING_AJAX )) {
return $title;
}
$settings = get_option('woo_payment_discounts_setting');
$settings = maybe_unserialize($settings);
if (isset($settings[$id]['amount']) && 0 < $settings[$id]['amount']) {
$discount = $settings[$id]['amount'];
if ($settings[$id]['type'] == 'percentage') {
$value = $discount . '% discount';
} else {
$value = wc_price($discount);
}
$title .= ' <small>(' . sprintf(__('%s', 'woo-payment-discounts'), $value) . ')</small>';
}
return $title;
}
Any idea how to do this?
Actually it shows a black "% discount" word and I need it green. I know how to create a CSS class, but I don't know how to implement that to this code. I'm sorry but I'm new on this. Thank you so much.
Upvotes: 1
Views: 640
Reputation: 254333
Try this:
public function wpd_payment_method_title($title, $id) {
if (!is_checkout() && !( defined('DOING_AJAX') && DOING_AJAX )) {
return $title;
}
$settings = get_option('woo_payment_discounts_setting');
$settings = maybe_unserialize($settings);
if (isset($settings[$id]['amount']) && 0 < $settings[$id]['amount']) {
$discount = $settings[$id]['amount'];
if ($settings[$id]['type'] == 'percentage') {
$value = $discount . '<span style="color:green;">' . __('% discount', 'woo-payment-discounts') . '</span>';
} else {
$value = wc_price($discount);
}
$title .= ' <small>(' . sprintf(__('%s', 'woo-payment-discounts'), $value) . ')</small>';
}
return $title;
}
It should work.
If you want to have the discount percentage number in green too, you will use this instead:
$value = '<span style="color:green;">' . $discount . __('% discount', 'woo-payment-discounts') . '</span>';
Or you can add a class:
$value = '<span class="discount-color">' . $discount . __('% discount', 'woo-payment-discounts') . '</span>';
And on your theme's styles.ccs
file you will addthe following rule:
.discount-color {
color:green;
}
Upvotes: 2