I
I
Ivan2020-04-27 12:53:38
WordPress
Ivan, 2020-04-27 12:53:38

Wordpress needs advice. Which plugin to choose for certain jobs?

Hello. I have a website, I want to make a discount on the first product in the amount of 20%. The problem is that I don't know how to do it. I strongly doubt that it is possible to do this without registration, because we need to somehow identify the user, right?

If I'm right, what is the best plugin for this? How do I get a discount on my first order? Naturally, a person should also write on the payment page that you will have a discount.

I ask you not to write something like "Create a promo code and don't fool yourself", this is not suitable for me, I need the site to give a discount if the first order.

For example, I saw this site https://inbenefit.com/woocommerce-%D0%BB%D0%B8%D1%...

I downloaded the second plugin "Ultimate Membership (WooCommerce)" from here, will it work with it? If not, then which plugin to choose.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2020-04-29
@youmixx

Found the answer.
I made a small function that returns the number of purchases already made by a person on the site. Works without registration. To be honest, I don’t quite understand when he saves how many orders someone has, the main thing is what he saves.

function check_count() {
        $id = get_current_user_id();
        $count = wc_get_customer_order_count($id);
        return $count;
    }

$id = get_current_user_id(); - get the person's id.
$count = wc_get_customer_order_count($id); - find out the number of orders.
return $count; - we return this quantity.
Then, to give out the discount itself, I did this.
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge');
    function woocommerce_custom_surcharge() {
        global $woocommerce;

        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;

        if(check_count() == 0) 
        {
            $summ = $woocommerce->cart->subtotal;
            $summ = ceil($summ / 100 * 20);
            $woocommerce->cart->add_fee("Скидка за первый заказ: ", -$summ);
        }
    }

$summ = $woocommerce->cart->subtotal; - find out the total amount of the entire order (not counting the cost of delivery, if any).
$summ = ceil($summ / 100 * 20); - The number 20 is how much to give a discount as a percentage. If so, do your calculations. ceil() - to round up to an integer.
$woocommerce->cart->add_fee("First order discount: ", -$summ); Well, we add the discount itself, it looks good.
Enjoy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question