我需要将颜色更改为代码的这一部分:
'% 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;
}
有什么想法吗?
实际上,它显示一个黑色的“%Discount”字样,我需要绿色。我知道如何创建CSS类,但不知道如何将此代码实现。 抱歉,我是新手。非常感谢。
答案 0 :(得分:2)
尝试一下:
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;
}