更改Wooccommerce上代码功能内的文本颜色



我需要将颜色更改为代码的这一部分:

'% 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;
}

知道怎么做吗?

事实上,它显示了一个黑色的"%折扣"字样,我需要它的绿色。我知道如何创建一个CSS类,但我不知道如何将其实现到这段代码中。对不起,我是新手。非常感谢。

试试这个:

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;
}

它应该起作用。


如果您也希望折扣百分比数字为绿色,您将使用以下内容:

$value = '<span style="color:green;">' . $discount . __('% discount', 'woo-payment-discounts') . '</span>';

或者您可以添加一个类:

$value = '<span class="discount-color">' . $discount . __('% discount', 'woo-payment-discounts') . '</span>';

在主题的styles.ccs文件中,您将添加以下规则:

.discount-color {
color:green;
}

最新更新