Edit woocommerce price displayed for logged in vs logged out users
- or -
Post a project like this1856
$$
- Posted:
- Proposals: 15
- Remote
- #2328629
- Completed
WORDPRESS ( WOOCOMMERCE AND PLUGIN) AND CMS EXPERT - QUICKEST DELIVERY GURANTEED 12 + YEARS
Mohali
✪ Top Web & Mobile - Laravel | WordPress | WooCommerce | AngularJS | VueJS | Android | iOS | APIs | NodeJS | Blockchain | Cloud Expert
Al Ain
Full Stack Web Developer with 13+ Years of Experience | Entrepreneur | Website Designer | Wordpres Developer | AI App Developer | Prompt Engineer | Python Programmer
Greater Noida
Leading Web Application and Mobile Appllication Development Company
Chandigarh
UI/UX Designer | WordPress Designer | Graphic Designer | Cartoon Portrait Artist | Embroidery Digitizer
Zongzhai
WordPress |Wocommerce | Core PHP | CodeIgniter| Magento | Bigcommerce | Prestashop | Responsive Design
Jaipur
⭐ ⭐ ⭐ ⭐ ⭐ Top Rated in Plymouth UK, 17+ Years Professional Experience, A+ Communications
Metuchen
1503621150813026138625991431505883250023613949892426448129516819090701854587274263
Description
Experience Level: Intermediate
I need a function modified to display woocommerce product prices in a certain way depending on if the user is logged in vs logged out. I have products that have a regular and sale price entered. I need it to display like this:
Logged in: *Sale Price* (Usually *Regular Price*)
Not Logged In: *Regular price* (Member price *Sale Price*)
So for example, I have a product with a regular price of $40 and a sale price of $30. I need the price on the product page to display like this:
Logged in: $30 (Usually $40)
Not Logged In: $40 (Member Price $30)
So far I have this in functions:
add_filter( 'woocommerce_get_price_html', 'custom_get_price_html', 20, 2 );
function custom_get_price_html( $price, $product ) {
if( $product->is_type('external') )
{
if( is_user_logged_in() )
$active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) );
else
$active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) );
if( $active_price > 0 )
$price = wc_price($active_price);
}
return $price;
}
This function works well for displaying the sale price for logged in users and the regular price for logged out users, but I need it modified to what I described above.
Logged in: *Sale Price* (Usually *Regular Price*)
Not Logged In: *Regular price* (Member price *Sale Price*)
So for example, I have a product with a regular price of $40 and a sale price of $30. I need the price on the product page to display like this:
Logged in: $30 (Usually $40)
Not Logged In: $40 (Member Price $30)
So far I have this in functions:
add_filter( 'woocommerce_get_price_html', 'custom_get_price_html', 20, 2 );
function custom_get_price_html( $price, $product ) {
if( $product->is_type('external') )
{
if( is_user_logged_in() )
$active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) );
else
$active_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) );
if( $active_price > 0 )
$price = wc_price($active_price);
}
return $price;
}
This function works well for displaying the sale price for logged in users and the regular price for logged out users, but I need it modified to what I described above.
Dan P.
100% (22)Projects Completed
21
Freelancers worked with
11
Projects awarded
27%
Last project
8 Nov 2022
United States
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
Dan, Can i see your website link for us to review and provide our feedback ?
779430
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies