简体   繁体   English

请如何在 wordpress 中的 php 代码中更改颜色

[英]please how to change color in php code in wordpress

i have this code to hide price in woocommerce until user login i want to change the message color that will appear "login to see price" the code is:我有这个代码来隐藏 woocommerce 中的价格,直到用户登录我想更改将出现“登录查看价格”的消息颜色代码是:

add_filter( 'woocommerce_get_price_html', 'bbloomer_hide_price_addcart_not_logged_in', 9999, 2 );

function bbloomer_hide_price_addcart_not_logged_in( $price, $product ) {

if ( ! is_user_logged_in() ) {

   $price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'login to see price', 'bbloomer' ) . '</a></div>';

  remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

  remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}

return $price;

}

You can use CSS to change price color, the class of price is .woocommerce-Price-amount , inject a html section in a hook.您可以使用 CSS 更改价格颜色,价格的 class 为.woocommerce-Price-amount ,在挂钩中注入 html 部分。

If it is single product page you can use woocommerce_before_single_product hook.如果是单个产品页面,您可以使用woocommerce_before_single_product挂钩。

add_action( 'woocommerce_before_single_product', 'price_red_if_not_logged_in', 10 );

function price_red_if_not_logged_in( $wc_print_notices, $int){
if ( ! is_user_logged_in() ) {
?>
<style>
.woocommerce-Price-amount {
    color: red;
}
</style>
<?php
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM