WooCommerce Gift Cards – Admin Screens


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>";