Zachary Powell

Software Programmer

Zachary Powell

Download my CV Send me a Message

Access Woo-commerce order Information

Zachary Powell - 01/02/2016

Overview

Recently, I have started using Woo-commerce more and more. In fact it has now become my go to standard for custom e-commerce websites, from simple sites that offer only a few products to large sites with 100’s of items. I have found this plug-in to be flexible enough to accommodate any requirements a client might have, be it custom payment gateways or even extra processing logic.

Being based on WordPress, it is as easy to override any of the woo-commerce code or use any of the many hooks to expand the code base.

I will do a number of blog posts around this plugin, exploring many of the different ways you are able to expand and change the code. Today we will be looking at how we can access a logged in users past orders and display that information on a custom page.

We are going to create a page called “Get Orders”, give it the slug “get-orders”, then in your sites theme directory create a file called page-get-orders.php.

File Setup

Start off with the top comment section. As with all WordPress theme files, a very basic example would be:

<?php
/**
 * Template Name: Get Orders
 *
 *
 * @package myCustom-theme
 */

Here we just give the file a name and assign it to the theme page.

$order_id = get_query_var( 'id' );

Next, we grab the ID of the order we actually want to look at. This is passed to the page as a get variable, so an example URL would be: woocommerce-website.co.uk/get-orders/?id=142

We might just want to see all the orders, but this is optional.

Get orders for logged in user

$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
  'numberposts' => $order_count,
  'meta_key'    => '_customer_user',
  'meta_value'  => get_current_user_id(),
  'post_type'   => wc_get_order_types( 'view-orders' ),
  'post_status' => array_keys( wc_get_order_statuses() )
) ) );

Now that the page is set up, we will run the actual code to get the orders. Using the WordPress get_post function and applying the ‘woocommerce_my_account_my_orders_query’, we are able to query Woocommerce for orders. Passing it the current users ID against _customer_user, we are given an array of all the current logged in users orders. If no user is logged in, this will not return any orders.

Access the Information

foreach ( $customer_orders as $customer_order ) {
    $order = wc_get_order( $customer_order );
    $order->populate( $customer_order );
    $item_count = $order->get_item_count();
    
    if ($order->get_order_number() == $order_id){
      $items = $order->get_items();
                        echo $order->billing_first_name;
                        echo $order->billing_last_name; 
                 }
}

We now have an array of orders $customer_orders, we can cycle through them. Taking each one, we get the order and then can check if it is the order ID we are looking for. Again, we might skip this step if we just want to print out the information of all orders.

Now that we have a WC_Order object ($order), we have access to a huge range of very useful fields and methods. Check out https://docs.woothemes.com/wc-apidocs/class-WC_Order.html for a look at these. The above example code has just a few but there are many many more.

Software I use

Zachary Powell - 21/01/2016

Today, we have a look at the software I use for development and just general computer use. As a software developer, I use a range of operating systems and programs.

Operating Systems

I use three different operating systems on a daily bases. OSX is my “main” as my main computer is now a Macbook Pro, while I have Ubuntu and Windows running in virtual machines.

OSX

Screen Shot 2015-12-30 at 14.17.23

As I said already, OSX 10.11 is my main operating system. When I am working on Android, iOS or web applications, I will be using OSX. It provides all the tools I need using the below software, although I do need to use other operating systems for tasks, most can now be taken care of within OSX.

Windows

Screen Shot 2015-12-30 at 14.19.24

Windows 10 is only now used when I need to develop software for windows or use a peace of Windows only software. This is not often done, but I still keep a virtual machine ready just encase.

Ubuntu

Screen Shot 2015-12-30 at 14.23.45

Ubuntu 14.04 is used again when I need access to a Linux operating system. There are a few projects I work on including LinuxonAndroid, where it is still much easier to work within Ubuntu to do this, giving me a great free and stable operating system for this work. Again, this is run within a virtual machine.

Developer Tools

During a normal day of work, I use a range of different software packages, depending mainly on the platform I am developing for.

XCode

Screen Shot 2015-12-30 at 14.27.37

XCode is the go to software tool for developing OSX/iOS applications. When ever a client needs something developed for these platforms, this is the tool I will use.

Android Studio

Screen Shot 2015-12-30 at 14.30.10

Android Studio is to Android as Xcode is to iOS. If a client needs native Android work doing, Android studio is the software I will turn to. In the past, I used Eclipse exclusively for Android development. However in the past year, Android Studio has become far more stable and includes some really nice features. It is now also the only officially supported tool by Google.

FileZilla

Screen Shot 2015-12-30 at 14.29.14

FileZilla is one powerful FTP client. Often, when I am working with a remote server or on a web application, I will be using FileZilla to easily transfer files to and from the remote servers.

Eclipse

Screen Shot 2015-12-30 at 14.32.01

As I said before, Eclipse used to be the tool I went for when it came to Android development. While it is still a tool I have ready to use, it does not often get used any more due to migrating to Android Studio. If a client however, does have an older code base and is only looking for small changes/improvements, I will likely use Eclipse to save them time and money.

TextMate

Screen Shot 2015-12-30 at 14.30.32

Textmate is, in my view, the best text editor available for OSX. It offers syntax highlighting for a range of languages and it is a great distraction free development tool. I will often do most of my web work within TextMate, along with other scripting style languages that do not require any kind of compiling.

VirtualBox

Screen Shot 2015-12-30 at 14.30.58

As said when I was talking about the operating systems, I use both Windows and Ubuntu within virtual machines. These are managed and controlled by VirtualBox, a great free virtual machine system.

MySQL Workbench

Screen Shot 2015-12-30 at 14.31.34

If a project requires the use of a MySQL database, then this is the software I will turn to. From just connecting to a pre-existing database to make changes or creating a completely new database, this software package allows you to do anything and everything you need to do from a nice GUI, without the need of the command line (although, I will admit from time to time, it can be quicker to use the command line).

Other Software

There is a range of softwares I use outside of developing. Below are just a few.

Mail

Screen Shot 2015-12-30 at 14.32.20

Before moving to OSX, Thunderbird was my go to Email client. However, after making the switch, I found that the default Mail client, included in OSX, did a better job. I have a number of mail accounts across platforms (Google, Microsoft, own servers etc), so a good mail client that can pull all these in is a must for me.

Skype

Screen Shot 2015-12-30 at 14.32.44

I have talked about Skype before when discussing the apps I use on my tablet. Again, it is often a very important tool during my day – from Skype calls with clients as well as talking with friends. It is my preferred go-to text/voice chat client, mainly due to its wide use and platform support.

Steam

Screen Shot 2015-12-30 at 14.32.59

In the odd moment I have time to unwind, I often like to play a game. While I do have an Xbox one, I really enjoy a lot of titles far more popular on desktop platforms, including the likes of Team Fortress 2 and Portal. Valve owned titles aside, Steam is the the best desktop gaming client, and now that so many titles have OSX support, I often find myself on here.

Chrome

Screen Shot 2015-12-30 at 14.32.53

Last but not least, Google Chrome is my web browser of choice. While it is pretty memory hungry, I have been an avid user since the very start, and using an Android phone as my daily device, I find Chrome gives the best cross platform support and syncing.

As always, feel free to leave questions and comments below.

Display location and custom pin on Google Map in iOS

Zachary Powell - 06/01/2016

Today we will look at how to Display the users current location within a Google Map, and also look at using custom pins in iOS. Much the same as we have already covered for Android HERE and HERE, also make sure to check out our last guide on setting up Google Maps for iOS HERE (if you have not already!)

Display User Location

Displaying the users location on the Google map within iOS is a very simple process. Once we have the map view set up, we just need to set myLocationEnabled to YES with self.mapView.myLocationEnabled = YES;. From here, we will have our location displayed on the map. However, the map will not move to the users current location or move the map as the user moves.

Jump to Users current location

To do this, we first need to make some changes to the mapview set up:

-(void)viewDidLoad{
...
    self.mapView.myLocationEnabled = YES;
    self.mapView.mapType = kGMSTypeNormal;
    self.mapView.settings.compassButton = YES;
    self.mapView.settings.myLocationButton = YES;
    self.mapView.delegate = self;
    [_mapView addObserver:self
               forKeyPath:@"myLocation"
                  options:NSKeyValueObservingOptionNew
                  context:NULL];
    dispatch_async(dispatch_get_main_queue(), ^{
        _mapView.myLocationEnabled = YES;
    });
...
}

So we have now added the myLocationEnabled, as well as adding the compass and myLocation button. We then need to set up a delegate to handle updating the map view to move to the users location. This is set by adding the Observer. We then need to create the actual function that will be called.

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {
       
        CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
        longitude = location.coordinate.longitude;
        latitude = location.coordinate.latitude;
        
        _mapView.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
                                                         zoom:14];
    }
}

The above code is called when ever the location changes. We get the new location object, take the longitude and latitude and then finally move the maps camera to that location. This way, the map will always be centred on the users location as they move.

Plot Marker with default pin

Much like in Android, creating a Marker and plotting it on the Map is very easy to do, but offers a range of features we can use to customise them. Lets first look at a very simple marker.

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(53.784426, -1.735840);
marker.title =  @"Test Pin";
marker.map = _mapView;

Here we create the new GMSMarker object then set its position and title, before finally setting its map as our map view. This is a very simple set up and plenty of other options are available check out THIS

Plot Marker with custom pin colour

Another example is setting the icon. We can either use a custom image or take the normal Marker and load a different colour.

UIImage *green = [GMSMarker markerImageWithColor:[UIColor greenColor]];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(53.785426, -1.735800);
marker.title = @"Green Marker";        
marker.icon = green;
marker.map = _mapView;

Here we create a green Marker icon, but we could use any UIColor.

As always, if you have any questions, comment below.

Samsung Galaxy S6 Edge – One Strange but loveable device

Zachary Powell - 01/01/2016

Intro

I change my device pretty often, at least yearly if not more often. I have in the past, owned a number of Samsung devices as well as phones from other various brands. From memory, my order of devices owed to my main day to day device:

  • HTC Magic
  • HTC Desire S
  • Samsung Note
  • Nexus 4
  • Samsung Note 3
  • Nexus 5
  • Samsung Note 4
  • Samsung S6 Edge

I have also owned, and have, a range of other devices for testing and development work, but these above have been my devices used as the day to day phone, not just a development tool. In this review, I will look over the Edge S6 as both a day to day device, and a development tool. For me, both are important. I want a phone that will keep up with my daily usage, many phone calls, text, emails, skype and also something that can be used to test new software.

Hardware

Lets first look at the device itself. Without solid hardware, a device simply wont keep up, no matter how good the software is. I am a heavy multi tasking user and have in the past found devices struggle to keep up and keep apps running.

The device itself has a glass front and rear, with the thin metal strip around the edge. If it was not for this strip, I think the device would be very difficult to hold. The glass is pretty slippery, and when holding it in your hand you really do feel like it could just slide out. Of course Samsung have now turned to the ‘darkside’. This phone is completely sealed – no replacing batteries or actually anything without a lot of time and heat pads (https://www.ifixit.com/Teardown/Samsung+Galaxy+S6+Edge+Teardown/39158). We also no longer get a SDcard slot. This sucks, but at 32GB, the phone has more than enough memory for me.

The front of the device has the normal Samsung layout of a hardware ‘home’ button, which this time round also doubles up as the finger print reader, along with two touch buttons, a back and a recent apps button. Personally, I like having the hardware keys, leaving all the screen free for apps etc, which on a smaller phone helps a lot.

2015-12-30 09.01.49

On the left side we have the volume rocker and on the right the power button. When holding the phone in your right hand, these positions are perfect – the volume rocker is easily reached with my index finger and the power button my thumb. This might be because of having larger phones in the past, but the general size of the phone seems perfect in my hand, small enough to hold and use one handed, but still big enough for the screen high resolution to be worth it.

2015-12-30 09.03.50 2015-12-30 09.04.05

On the top we find the SIM card slot, IR transmitter and a microphone. This might seem like quite an odd position for the SIM card slot, but because of the curved screen we are not left with very much thickness on either side. The top side is really the only location it could now fit.

2015-12-30 09.03.58

Finally along the bottom we have the 3.5 headphone jack, micro USB (no USB-C here) port, another microphone and one lone speaker.

2015-12-30 09.03.25

Spec

The specs of the Edge S6 has the same internal hardware as the S6, the only real difference being the funky curved screen. I will look at this more shortly but first the devices complete spec:

  • Screen – Curved 5.1 inch screen with a resolution of 1440 x 2560 pixels (~577 ppi pixel density)
  • Chipset – Exynos 7420
  • Storage – 32GB
  • RAM – 3GB

For the complete spec check out

http://www.gsmarena.com/samsung_galaxy_s6_edge-7079.php

Nothing hugely different here to most flagships, although this is the first Exynos device I have used. It will be very interesting to see how far Samsung have come with their own SoC (System on Chip).

A quick run of some bench marks have given the below results. While benchmarks are not always a good example of real world performance, they are a great place to start!

2015-12-29 22.35.02 2015-12-29 22.33.38 2015-12-29 22.32.06

That Screen!

Of course the main selling point of the S6 Edge is its curved screen. Other than this, it is just the S6 after all, but what a screen it is! While the curve itself has little use in terms of functionality, it does change the shape of the phone in a way ,that I feel, makes the phone much easier to hold and gives the effect that its much thinner than it actually is.

2015-12-30 09.01.49

Other than the curve, the screen is a beautiful AMOLED panel, which produces an amazing colour range, and of course perfect blacks. The viewing angles are pretty damn perfect as well. This honestly has to be the best screen I have ever seen on a device.

Camera

As with every years flagship phones from Samsung, they have bumped the cameras spec, producing some really lovely images. The front camera is not really anything to write home about. It works and produces OK images in low light, but is just a standard front facing camera. If you’re a selfie lover, this might not be a selling point for you.

Personally, one of the points I look for in a new daily use phone is a good rear camera. As you may have noticed from the (pretty awful) photos of the phone in this post, I do not own a stand alone camera. I am by no means a photographer and never justified buying one. I am glad (for your sake as well as mine) that this phone lives up to that goal. Although its very dark and pretty miserable outside, the phone does a pretty good job at capturing detailed images both in low light and well lit areas.

BB-8 in a well lit room before his next advantage freaking out the dogs

BB-8 in a well lit room before his next advantage freaking out the dogs

Blaine in a dim room who does not stay still for more than a few seconds!

Blaine in a dim room who does not stay still for more than a few seconds!

The depressing weather outside...

The depressing weather outside…

Fingerprint Reader

I just wanted to stop by that other interesting hardware point of this years Samsung flagship phones, the fingerprint reader. I have used a number of readers in the past, all the way back to the Motorola Atrix, but this is the first one that actually works more times than doesn’t. Setting up new fingers is very easy to do and just involves pressing the finger on the home button a number of times so it can record from all angles. The more angles you do, the better the final result. To unlock the phone all you now have to do is press down the home button (to wake it) and hold your finger on the button for a few seconds to allow the reader to pick up your finger.

While from time to time it does fail to pick up the finger it does a pretty good job, and is finally to a point where fingerprint readers are a viable and useful method for locking and securing a phone.

Software

Over the years, Samsung have been slated for their Android “skin” TouchWiz and the large amount of extra apps they preload on devices, causing many of their older flagship phones to struggle with multi tasking due to a lack of any free RAM. After picking up my S6 Edge, Samsung announced on twitter that they where doing an open beta test of the new Android 6.0 update for all UK owners. Of course, I jumped at the chance to give marshmallow a go and updated right away.

This does mean that the software I am reviewing is very much subject to change, although even as a beta I have struggled to find any crashes or slow-downs.

Android 6.0

2015-12-30 09.05.01

Above is the current build my phone is running. We are looking at Android 6.0 (interestingly not 6.0.1) with all the normal Samsung extras (KNOX etc).

2015-12-30 09.45.03 2015-12-30 09.04.48

Over the years, Samsung have slowly dialed back the bloat that is including on their devices, and the newest version of TouchWiz is no different. Now only a handful of “S” apps are included by default and, like with the last generation, while you can not uninstall these apps, you can “disable” them, which stops them running and removes them from your app launcher.

I do hope Samsung makes some final adjustments to their skin before it launches, as stable as above is, an example of a couple of points where they have really missed the mark on design. The White background with Blue highlights for the notification draw looks really bad. It might be a personal thing, but I really don’t like it. The same can be said for the “bubbles” around app icons that are not Samsung apps. Again,  what is going on here !?!  OK, it does say a lot about how far they have come.

TouchWiz growing up

But I do feel that the newest version is a step back from their Android 5.0/1 software originally shipped with the device.

2015-12-30 09.43.16 2015-12-30 09.05.12 2015-12-30 09.05.29

This reduction of “bloatware” really can be felt. Along with the Android 6.0 improvements we now get about 1.1GB of free RAM for apps to gobble up – still not as great as other more stock android devices, but its not a bad result by Samsung and the phone really does fly. Many of the apps have also be updated with a new colour pallet which overall I do really like. It is strange to me that they can come up with some really nice simple design work for the apps like the above Phone and “Smart Manager” apps, but then miss the boat by so much with the launcher.

The Camera app itself also get a nice bump in features, with all the normal features but now with the option to shoot in RAW. Again, a great feature for someone like me who doesn’t have a DLSR, but may well want to use the added benefits of the RAW file format.

Wrap up

The Samsung S6 Edge is certainly a strange device. Does the curved screen really bring much to the game? I am not convinced, but what it does do, is allow the device to feel much thinner and I like that.

Other than that this is the same device as the S6, but that is not a bad thing at all. The hardware is solid and well built as you expect from Samsung and the new addiction of Android 6.0 brings some really nice extra features and an always welcome speed boost.

This is a phone that I would certainly recommend to anyone looking to get a new flagship phone and of cause, the S7 will be just around the corner and likely bring even more improvements, but in the fast moving world of phone hardware you can not stand waiting around because a new device will always be around the corner.

As always, please comment below with any questions.

Using Google maps in iOS

Zachary Powell - 30/12/2015

Today, we will look at setting up and using the Google Maps SDK on iOS devices. This leads on from our look at doing the same on Android HERE.

Setting up

First and foremost, make sure you have the most up to date version of Xcode. The Google Maps SDK only works for version 6.3 and above. The current version is 7.2 and I would recommend using this version for iOS 9 support.

To install the Google Maps SDK, we will be using CocoaPods. CocoaPods is an open source dependency manager for both Swift and Objective-C projects. If you don’t already have cocoapods installed, please do so now by opening a terminal and typing the below command:

sudo gem install cocoapods

Installing

If you are not using a pre existing project, now is the time to create one. Create a simple Single View Application.

Screen Shot 2015-12-21 at 20.21.08

Next we need to create a file called Podfile in the project directory. This file defines our projects dependencies, which in this case will be Google Maps. Open this file and give it the below contents:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
pod 'GoogleMaps'

Save this file and then open a terminal within the directory containing the Podfile.

in this directory run the below command:

pod install

This will install the Google Map SDK for us. Once complete, close Xcode and then open (double-click) your project’s .xcworkspace file to launch Xcode. From this time onwards, you must use the .xcworkspace file to open the project.

Get API Key

Getting the key is pretty straight forward, but best described in the official guide from Google. Check out the details HERE

Using Map

Below is the most simple map set up we can do (future posts will look at more advanced features).

#import "YourViewController.h"
@import GoogleMaps;

@implementation YourViewController {
  GMSMapView *mapView_;
}

- (void)viewDidLoad {
 
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                          longitude:151.20
                                                               zoom:6];
  mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  self.view = mapView_;
}

@end

So we import the GoogleMaps library, then we create a GMSMapView object. This allows us to create a view within the ViewController that will display the Map on the Screen.

Then, we create a CameraPosition object. Initialising the Map with this will make the map display at that location and zoom level.

And thats it the most simple Google Map created.

As always if you have any questions leave them below.

“ Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”

-Martin Fowler