jeudi 4 mars 2021

Woocommerce dynamic pricing via content-product.php - Display vip prices with discount to non members in product card

Hi I would like to do the following sadly not working... anyone have an idea what i could use there to obtain the result i want?

I'd like to display the price that my vip members have to the visitors that are not yet having an account on the site.

For this, I used if and else function on the content-product.php page to detect users with active membership and with the slug from the woocommerce membership.

The first price is without discount when VIP users are logged in. The second price is with vip discount for all other visitors.

I am trying to give it such as a if and else variable but i m bugging on it since a few days, any help would be greatly apreciated.

I am not sure if I am missing something at the end or if it is just impossible to declare wc_memberships_get_user_active_memberships as depending what I try it says that wc_memberships_get_user_active_memberships is already declared in the theme... which sounds strange, so I have try to simplify it with this part of code.

The code seeems to deliver only the price for the vip, or the price for the non vip, but not possible to display the prices dynamically so that the vip user don't get a double reduction of the value of the vip discount i created once logged as a vip user on the same page.

I've try a few other things for this, but issues are always the same or it's the syntax error with the , in the echo price_val, symbol that comes out as error or it's with the echo.

Can someone help to write this properly?

I have try also a few other methods find on Stackoverflow and w3school to build a simple if else function but it didn't worked neither. Not sure if i am missing to put may be and endif somewhere. I just would like to place it in this small php part.

<?php  
                        
                    $memberships = wc_memberships_get_user_active_memberships( $user_id );

                    if ( ! empty( $memberships = 'vip' ) ) {
                    echo $price_val, $symbol; 
                    } else {
                    
                    if ( ! empty( $memberships = $user_id ) ) {
                    echo $price_val - $vip_discount, $symbol; 
                    }
                           }
                    ?>

Aucun commentaire:

Enregistrer un commentaire