Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey all …

    This was the last part of my code needed to get a booking system working.

    I used the plugin appointment calendar https://www.ads-software.com/plugins/appointment-calendar/

    I decided to go with the apcal_mobile version of it for now, so I edited the appointment-calendar-mobile.php file within the plugin directory and around line 92, I entered the following code:

    global $current_user;
    			get_currentuserinfo();
    			$customer_credits = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$current_user->ID' AND meta_key = 'wpcf-credits'" );
    			$new_creds = $customer_credits - 1;
    			$wpdb->update('wp_usermeta', array('meta_value' => $new_creds), array('meta_key' => 'wpcf-credits', 'user_id' => $current_user->ID), array( '%d' ), array( '%s' ));
    			error_log( "user id is $current_user->ID", 0 );

    I’ve obviously had to secure certain pages, which is all down to how you want to setup your pages, but when I have finished the site, I will link it here to let you see it working.

    made a mistake in my previous post. I put the code into woocommerce-functions.php

    Thread Starter StevenWilliams

    (@stevenwilliams)

    Hi Ankit,

    Yeah, a buffer time would be suitable, I just thought it’d be easier to block the current day and book from the days that follow, as it’s what is closest to what I need.

    Thanks
    Steve

    Thread Starter StevenWilliams

    (@stevenwilliams)

    Thanks for the update!

    One of the problems with the calendar currently is that it is also possible to set a time in the past. Is there a way that I can just set the default position as tomorrow rather than today? Or is that the expected behaviour?

    I’ll try to be more specific:

    Due to timezone issues and such, it’s possible when you click on “today” (the current day you make a booking), that you can also select a time available in the past. I would like to somehow, just prevent people from booking on the same day and force them into only being able to begin from tomorrow.

    Is that the expected behavior? Or is being able to book a time that very day supposed to be what is supposed to happen?

    This is the second component of my credits system, this is the part that when a payment is completed, the credits are added to the usermeta > wpcf-credits field. I’ll repeat just for conciceness that I got this extra field by using the plugin called ‘types’

    function credits_add_quantity($order_id) {
    	global $wpdb, $woocommerce;
    	$order = new WC_Order( $order_id );
    	$user_id = (int)$order->user_id;
    	if ( count( $order->get_items() ) > 0 ) {
    	foreach( $order->get_items() as $item ) {
    
    		$quantity=$item['qty'];
    
    	}
    	}
    		$quan = intval($quantity);
    		$customer_credits = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = 'wpcf-credits'" );
    		$newcredits = $quan + $customer_credits;
    		$wpdb->update('wp_usermeta', array('meta_value' => $newcredits), array('meta_key' => 'wpcf-credits', 'user_id' => $user_id), array( '%d' ), array( '%s' ));
    }
    add_action('woocommerce_order_status_completed', 'credits_add_quantity');

    I put this code into my wordpress-functions.php file at the very bottom.

    If anyone can suggest improvements to my code, by all means let me know.

    I will choose a booking system today and try to implement the credits system into that.

    I thought I’d come back and quickly explain what the code I pasted does.

    In my header.php, I put this code so that at the top of every page, a check is made to see if the user is logged in or not. If not, they are directed to the woocommerce register/login page. If they are logged in, it shows their display name plus the number of credits that they have per the API from the WordPress Types plugin.

    I found the following plugin: https://www.ads-software.com/plugins/types/

    What I did was create a new user meta field called “credits” and started from there.

    <div id="headertext-main">
    
        <?php
    	/**
    	 * steve's sauce
    	 */
    
    		if ( is_user_logged_in() ) {
    		global $current_user;
    		get_currentuserinfo();
    		$customer_credits = types_render_usermeta_field("credits", array("user_current" => "true", FIELD_VALUE));
    
    		echo 'Welcome ' . "<a href='?page_id=43'> $current_user->display_name </a>";
    		echo "<a href='?product=tutoring-credit-1h'>($customer_credits) </a>";
    		echo "<a href='?page_id=48'>logout</a>";
    
    		} else {
    		  echo 'Welcome visitor! ';
    		  echo "<a href='?page_id=43'>Click or touch to login/register.</a>";
    		}
    
    	/**
    	 * steve's sauce
    	 */
    
    	?>
        </div>

    I know my code sucks, but as it stands, it’s working. But this pretty much displays in my header the number of credits the user has. I am currently working on code to put behind Woocommerce orders and then finally for the calendar booking system that I’ll use and I’m more than willing to come back to this thread to share my future code with any of you guys who might find it useful.

    I haven’t done any coding since leaving Uni 6-7 years ago, so I have no idea how I’d even create an addon out of all of this, but I am sure there are some very smart people here that can give us a few pointers that would allow us to create a basic implementation.

    Did you find a solution to this?

    I am desperately trying to find a similar solution, but have found absolutely nothing so far.

Viewing 8 replies - 1 through 8 (of 8 total)