Category Archives: Plugin Development

WooCommerce Gift Cards – Admin Screens

UPDATE: PLEASE READ THIS POST

So now that I have the plugin template structure in place I need to look at creating the admin menu section.

I have chosen to go for a dedicated menu section rather than a sub menu under the settings. This will ensure we can clearly distinguish between the Gift Cards, Products and other sections of the system.

Creation the Administration Menu

To create a new admin menu section I will simply include the following information in the “pux-woocommerce-giftcards.php” file in my plugin folder.

/**
 * Configure Admin Menu
 */
add_action('admin_menu', 'pux_register_giftcards_menu_page');
function pux_register_giftcards_menu_page() {
 add_menu_page('pux-giftcards', 'Gift Cards', 'manage_woocommerce', 'pux_woocommerce_giftcards', 'pux_woocommerce_giftcards_settings', null, 56);
}

If you wish to understand more visit the wordpress pages that explain the adding of administration pages and more specifically the “add_menu_page” function.

Essential, I have configured the menu settings with:

  • A unique name of “pux-woocommerce-giftcards”
  • The menu item will be named “Gift Cards”
  • Access rights will be granted if the user has “manage_woocommerce” permissions
  • The page name when click is called “pux-woocommerce-giftcards”
  • The action for that page is “settings”
  • There is no image file to show for the menu
  • The position on the left hand menu will be 56, which places it after the Products section of WooCommerce.

Creating the Settings Page for Gift Cards

To configure the page, we simply need to create the function called “pux_woocommerce_giftcards_settings” which will handle the display of the Gift Card Configuration page.

Below is the function that I will include as a place holder for future development.

function pux_woocommerce_giftcards_settings(){
 echo "<h1>Gift Cards Administration</h1>";
}

WooCommerce Gift Cards – Plugin Template

UPDATE: PLEASE READ THIS POST

So to get things started I have created a new plugin template which to start with doesn’t include much except the base files and information needed for WordPress to identify it as a plug in.

In the “wp-content/plugins” folder I create a new folder called “pux-woocommerce-gift-cards”. The naming convention I am going to follow is “[uniqueID]-[system]-[pluginname]”.

  • [uniqueID] is something specific to me (hopefully) and will be used to prefix all of my files, folders, functions and variables. This ensures a greater chance that it will not clash with other plugins.
  • [system] will simply be a reference to the plugin I am extended. I will expect this to be optional as we could in theory create a plugin for wordpress itself, but as this plugin will extend the WooCommerce plugin it may be useful to make some identifying link.
  • [pluginname] is simply a name for my plugin. In this case it will be “giftcards”.

The first file to include in this folder will be one named “pux-woocommerce-giftcards.php”. Within this file we will need to include the following at the top of the file.

<?php
/*
Plugin Name: WooCommerce Gift Cards
Plugin URI: http://www.pu43x.co.uk/
Description: Extends WooCommerce to allow customer to purchase gift cards that can be used to purchase product in part or full payment.
Version: 0.0.1
Author: Gareth Davies
Author URI: http://www.pu43x.co.uk
License: GPL2
*/

?>

Once this file is saved it will become visible in the Plugins page in the WordPress admin screens and be available for activation.

 

WooCommerce Gift Cards

UPDATE: PLEASE READ THIS POST

So I have decided to try and create my first every plugin for WordPress, instead of focusing on something easy I have decided to jump in the deep end of the pool. However I am unaware of how deep the pool is or what fluid it holds!

Either way this post will initial focus on the areas of WooCommerce and WordPress I will to hook into and adapt.

Initial Idea:
I manage a website for a friend that sells products on line. I decided to install WordPress and then the WooCommerce plugin for the online shop capabilities. There was a request the other day from a customer who was wondering whether Gift Cards could be purchased online. I thought there was to likely be a plugin for such a scenario but after a bit of search came up with nothing.

WooCommerce already provides a coupon type functionality which allows any number of user to use, as long as they know the code. Coupons can be configured in several ways:

  • Cart Discount Amount
  • Cart Discount Percent
  • Product Discount Amount
  • Product Discount Percent

This is a great feature to use but is unsuitable for a Gift Card type scenario.

So what do I mean when I say Gift Cards? Well, if a customer really likes your products and wants to purchase an item for somebody else, but is unsure which items they would like, they could simply purchase a Gift Card with a pre-set amount on it.

This Gift Card can then be passed (or sent through email) to the lucky recipient who then is able to come back to the your site, browse the products for something they like. Once they have found something they can progress very as normal through the check out process but there is an option on the payment page to pay by Gift Card.

Payments by Gift Card can be taken in part or in full depending on the customers Gift Card balance and how much the total value is. Any remaining balance should be taken as normal through their preferred payment gateway.

Planning the Solution

As this is my first ever plugin WordPress I have some serious reading to do. For example I know there are hooks which allow applying filters and actions to areas of code but I am not sure of the flexibility of these.

There is also the way for which the plugin is build and deployed. The very last thing you want to do is edit any code outside of your plugin, unless it is apart of your theme, but the end code is to ensure the plugin is what it says. A piece of code that simply plugins into WordPress without any other modifications. Other things to also consider are upgrades and un-installing plugins as these can include the same (if not more) amount of code to install the plugin in the first place.

Below is a list of areas that I need to develop.

  • Admin Area Menu
    This menu item should appear below the “Products” section for which WooCommerce installs. There will be various sub sections to this menu which will be details further on but initially looking at “Current Gift Cards (and amounts)”, “Ability to Create Gift Cards”, “Edit Gift Cards”.
  • Database table to hold Gift Card Information. Proposed information to include is “Initial Amount Value”, “Amount Left”, “Date Created”, “Expiry Date”, “Gift Card Code”, “Gift Card Pin”, “User Email”, “Created By”
  • Purchase Process for Customer
  • Gift Card Value Checking
  • Redemption Process for Customer

Gift Card Security is probably one of the main questions to consider here. What we have to consider is how will each gift card be secured so that only a valid user is able to redeem the value. Looking at other other systems in place for other physical stores it seems to be a combination of Gift Card number and a 4 digit PIN.

We could go a level deeper and link each Gift Card to a specific customer account but I think this might introduce unneeded complexity. For one, the customer may not know the email address of the recipient and sometimes it is valid that a Gift Card could change hands.

This brings us onto the delivery of Gift Cards. Do we simply provide a unique code and PIN for the customer to pass on, or should the shop physically ship a pre-printed gift card. I suppose this really depends on your customer as the site I will be building this plugin for really focuses on presentation and would be fitting to provide a physical Gift Card which can be presented as a present to the recipient.

Implementation

I will create a post for each of the sections above so to not make this post extremely long.