Let’s go shopping!

So I haven’t done an official launch of my website’s shopfront, but I am excited about it unfolding live and in a more organic nature.

In the meantime, I am going to write a more technical post about how I managed to accomplish the shop up to this point. Probably the majority of people reading this blog are here for the cake posts, I know, but you just never know who may be more interested in the technical aspect of it (especially considering its unusual complexity of requiring multiple shipping origins).

Overview of technologies

There are a number of decent ones available, just find one that meets your needs. I am currently with a business package on Hosting Australia who provide excellent pricing and brilliant service, even on weekends.

You can either get this bundled with your web hosting package, or you can pay for one separately to have installed along with your website manually. Be sure to choose which one suits your needs. Please don’t disregard this step if you are intending to do online sale transactions to protect your customers’ data!

 Why reinvent the wheel? There is a myriad of wonderful WordPress plugins that are absolutely free, so why not make the most of it? What’s great about WooCommerce are the number of additional plugin extensions you can get for it! Here is a list of the ones that I am (at this point in time) using to provide a seamless online shopping experience on my website. And best of all, these are all (at the time of writing this article) ABSOLUTELY FREE! 🙂

WooCommerce Extension NameExtension Description
Multiple Packages for WooCommerceA simple UI to take advantage of multiple shipping packages without PHP knowledge
Payment Gateway Based Fees and Discounts for WooCommerceWooCommerce Payment Gateways Fees and Discounts.
Smart Send Shipping for WooCommerceAdd Smart Send Australian shipping calculations to Woo Commerce.
** REQUIRES VIP ACCOUNT **
Woo Checkout Field Editor ProCustomize WooCommerce checkout fields(Add, Edit, Delete and re-arrange fields).
WooCommerce Print Invoice & Delivery NotePrint Invoices & Delivery Notes for WooCommerce Orders.
WooCommerce SquareAdds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.

Now, before you go and just install everything willy-nilly, I will point out that WooCommerce on its own is a powerful plugin and I would probably say most people don’t necessarily need to add anything else on. But, in my case, I had some small things that I needed to tweak, and these extensions worked beautifully.

Customisations

Now wouldn’t it be lovely if every single thing worked straight outta the box?! While I would say 99% did, the complication I faced was that not everything I intended to sell would be shipped from the one origin address. Something that I thought there would be a plugin readily available for, but apparently not quite.

So what I did was divide and conquer the problem. I first installed the extension “Multiple Packages for WooCommerce” (mentioned in table above). This could then handle the splitting of packages via use of the product shipping class, so each package has its own set shipping fee. (This incidentally handles the issue of products that need to be limited to pick up only, ie fresh baked goods, fragile goods, or in the other industries, larger items).

The next stage was to then apply that same stream of logic (ie using the product shipping class) to then differentiate shipping origin address in the SmartSend plugin (I happened to be using SmartSend as my courier option, however I am sure there are equivalent courier plugins for other services in other countries). Now, as far as I am aware, I could have requested assistance for this issue directly with SmartSend and the developers probably could have created a solution for me. However, what kind of software programmer would I be if I had not at least attempted to resolve this for myself?

Overview of existing wordpress plugin Development

What you’ll need to develop an existing WordPress plugin:

  • FTP client, such as FileZilla client
  • Your FTP credentials to log onto your website’s hosting files
  • A PHP editor, such as Notepad++
  • AgentRansack (optional) – a fast and efficient way to search through folders, based on search terms “filename” and “containing text”.

Once you’ve logged into your website’s FTP, you can then locate the plugin you want to develop under directory (in this particular example, we are going to develop on the SmartSend plugin, located under public_html/wp-content/plugins/woocommerce-smart-send-australian-shipping).

I tend to download the entire directory to my local drive, and then make a copy under a BACKUP folder. Just in case I mess something up, I can then roll back hehe

Now, the development that I did, all happened to be contained in one file: smartsend-plugin.php.

I won’t delve into specific details at this stage of what I changed, however here is an overview.

Problem: Need to assign a different shipping origin for Bakels products

Solution:

  1. Create new Shipping Class “Bakels” as part of Multiple Packages plugin use, which splits the cart items by Shipping Class
    WooCommerce Shipping Classes

    WooCommerce Shipping Classes

  2. In the product itself, you’ll need to select “Bakels” shipping class so that they correlate
    Assign shipping class to product

    Assign shipping class to product

  3. Edit smartsend-plugin.php file, add new fields in init_form_fields method
    Updated SmartSend plugin settings page

    Updated SmartSend plugin settings page

    • Add new “Select” element: drop down list of all the registered Shipping Classes – will be Bakels
    • Add new form fields: secondary Origin Address details which correlates to that specific Shipping Class – where the Bakels shipping class items will be shipped from
  4. Edit smartsend-plugin.php file, where in the code it calls the setFrom method, insert code such that pseudocode is
    For each item in shopping cart
       If item has shipping class "Bakels"
          Call setFrom method using Secondary Origin Address
          break;
       Else
          Call setFrom method using Primary Origin Address

I think that covers it – not bad eh? Then when in use, you’ll see:

Cart split

Cart split

A useful tip – when developing PHP on WordPress, it’s hard to debug. Learnt this nifty little piece of code that you can insert into PHP that will dump to the output anything you need, example:

var_dump($shopping_cart)

Happy coding everyone! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *