Mycred Woocommerce Plus 40 1610625736 1
Info Duotone Icon

Description


The myCred WooCommerce Plus addon helps you award points to your WooCommerce store users using the myCred points management system. What’s special about this addon is that it will automatically award coupons to users whenever they successfully achieve a higher rank and badge.

Clock Counter Clockwise Duotone Icon

Version Log


List Magnifying Glass Duotone Icon

Additional Content


Lifebuoy Duotone Icon

Support


We provide technical support for myCred WooCommerce Plus through our community forums. Do you need support? Visit this link and post your issue!

  1. Avatar for stinq stinq says:

    Please update myCred WooCommerce Plus 1.7.5 to 1.8.1. @Steve

  2. Avatar for stinq stinq says:

    Hello everyone,

    I’d like to share a script I’ve developed for creating a reward system in WooCommerce using the MyCred plugin. This script rewards users with points for each purchase, and displays the number of points they would earn or need for each product, cart, and during checkout.
    Basically it makes what myCred Woocommerce Plus addon does…
    Here’s the code:

    Here’s the code:

    // Reward users with points for each purchase
    function mycred_pro_reward_points_for_purchase( $order_id ) {
        // Get the order
        $order = wc_get_order( $order_id );
    
        // Get the user
        $user = $order->get_user();
    
        // If the user is a guest, return early
        if( ! $user ) {
            return;
        }
    
        // Get the total order cost
        $order_cost = $order->get_total();
    
        // Calculate points (10 points per $1)
        $points = $order_cost * 10; 
    
        // Get the myCRED account of the user
        $account = mycred_get_account( $user->ID );
    
        // If the account was found, add points
        if( $account ) {
            // Assumes that your point type key is "mycred_default"
            $balance = $account->balance->point_types->mycred_default;
    
            // Add points to the user's account
            $balance->add( $points, 'Reward for purchase', $order_id );
        }
    }
    add_action( 'woocommerce_order_status_completed', 'mycred_pro_reward_points_for_purchase' );
    
    // Show points to be earned on product page
    function mycred_pro_show_points_on_product_page() {
        global $product;
    
        // Get product price
        $price = $product->get_price();
    
        // Calculate points to be earned
        $points = $price * 10;
    
        echo '<p class="points-earned">Purchase this product to earn ' . round($points, 2) . ' points.</p>';
    }
    add_action( 'woocommerce_single_product_summary', 'mycred_pro_show_points_on_product_page', 25 );
    
    // Show points to be earned and points cost on cart page
    function mycred_pro_show_points_and_balance_on_cart() {
        // Get cart total
        $cart_total = WC()->cart->total;
    
        // Calculate points to be earned and points cost
        $points_earned = $cart_total * 10;
        $points_cost = $cart_total * 30;
    
        // Get current user and their points balance
        $user_id = get_current_user_id();
        $points_balance = mycred_get_users_balance( $user_id );
    
        echo '<p class="points-earned">Complete your purchase to earn ' . round($points_earned, 2) . ' points.</p>';
        echo '<p class="points-cost">This cart total is equivalent to ' . round($points_cost, 2) . ' points.</p>';
        echo '<p class="points-balance">Your current balance is ' . round($points_balance, 2) . ' points.</p>';
    
        // Notify user if they have enough points to cover the purchase
        if ($points_balance < $points_cost) {
            echo '<p>You don\'t have enough points to cover this purchase, but you can still purchase with $.</p>';
        } else {
            echo '<p>Congrats! You have enough points to cover this purchase.</p>';
        }
    }
    add_action( 'woocommerce_cart_totals_after_order_total', 'mycred_pro_show_points_and_balance_on_cart' );
    
    // Global variable to check if checkout has already run
    $checkout_has_run = false;
    
    // Show points cost and points balance on checkout page
    function mycred_pro_show_points_and_balance_on_checkout_updated() {
        global $checkout_has_run;
    
        // If checkout has already run, return
        if($checkout_has_run){
            return;
        }
    
        // Get cart total
        $cart_total = WC()->cart->total;
    
        // Calculate points cost
        $points_cost = $cart_total * 10;
    
        // Get current user and their points balance
        $user_id = get_current_user_id();
        $points_balance = mycred_get_users_balance( $user_id );
    
        echo '<p class="points-cost">This order total is equivalent to ' . round($points_cost, 2) . ' points.</p>';
        echo '<p class="points-balance">Your current balance is ' . round($points_balance, 2) . ' points.</p>';
    
        // Notify user if they have enough points to cover the purchase
        if ($points_balance < $points_cost) {
            echo '<p>You don\'t have enough points to cover this purchase, but you can still purchase with $.</p>';
        } else {
            echo '<p>Congrats! You have enough points to cover this purchase.</p>';
        }
    
        // Set that checkout has run
        $checkout_has_run = true;
    }
    add_action( 'woocommerce_review_order_after_order_total', 'mycred_pro_show_points_and_balance_on_checkout_updated' );
    
    // Show points to be earned on checkout page
    function mycred_pro_show_points_earned_on_checkout() {
        // Get cart total
        $cart_total = WC()->cart->total;
    
        // Calculate points to be earned
        $points_earned = $cart_total * 10;
    
        echo '<p class="points-earned">Complete your purchase to earn ' . round($points_earned, 2) . ' points.</p>';
    }
    add_action( 'woocommerce_review_order_before_order_total', 'mycred_pro_show_points_earned_on_checkout' );
    

    Remember to add this to your functions.php file…

    I hope this proves useful! Feel free to modify it as per your needs.

  3. Thanks @stinq – much appreciated!

Continue the discussion at meta.festingervault.com

Participants

FestyBot
Martin
stinq
Shield Check Duotone Icon

VirusTotal Scan Report


/…

Scanning…

This file is currently being scanned.

List Bullets Duotone Icon

Details


Version

1.7.5

Status

Last Updated

Published

Downloads

Views

113

Demo Content

Yes

Original License

No

Original License

No

Files included

No files included found

Tags