简体   繁体   English

登录后如何在商品下显示价格 - wordpress

[英]how to display prices under products after login - wordpress

I need a free way to display prices after the customers login into my e-commerce website我需要一种在客户登录我的电子商务网站后免费显示价格的方式

i'm using woocommerce in wordpress我在 wordpress 中使用 woocommerce

I used a plugin named "Prices only members" and it hide the prices but after loging in it doesn't show the prices for the products我使用了一个名为“Prices only members”的插件,它隐藏了价格,但在登录后它不显示产品的价格

Any help please I'm not looking for not-free plugins请提供任何帮助我不是在寻找非免费插件

Described above all the tries上面描述的所有尝试

A coded solution would be to use the is_user_logged_in() WordPress function like this:编码解决方案是使用is_user_logged_in() WordPress function像这样:

if(is_user_logged_in()){
// output price
}

For this use case you need to use this custom code for simply hiding price before login in function.php or in any custom plugin:对于此用例,您需要使用此自定义代码在登录 function.php 或任何自定义插件之前简单地隐藏价格:

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

function hide_price_add_to_cart_not_logged_in( $price, $product ) {
   if ( ! is_user_logged_in() ) { 
      $price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'wordcommerce' ) . '</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;
} 

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

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