Skip to content

Instantly share code, notes, and snippets.

@drawcard
Last active May 7, 2017 02:29
Show Gist options
  • Save drawcard/d63bfaede19696f0cb8447cd77e2a226 to your computer and use it in GitHub Desktop.
Save drawcard/d63bfaede19696f0cb8447cd77e2a226 to your computer and use it in GitHub Desktop.
WooCommerce - Updating old theme override files to latest version

The Problem

Let's say you've inherited a theme from a client that some other developer made a long time ago, and your job is to update the code and figure out what stays and what doesn't.

Occassionally WC will update its core template library and this will get out of sync with any overrides in a given theme's /woocommerce/ folder. WC will send an alert in the WP backend that various templates are out of date and need updating. The theme will need its override files updated.

(Version examples for this demo: 2.1.1 is old, 3.0.0 is latest)

Identification

Go to https://xxxxxxx.zzz/wp-admin/admin.php?page=wc-status and scroll to Templates to see what files are problematic.

Checking for differences

The easiest way to see the differences in a theme file is to do a comparison (diff) between releases (tags) in Github.

  • Go to https://github.com/woocommerce/woocommerce/compare/2.1.1...master#files_bucket
    • Change "2.1.1" to any version number you want to compare
  • Press Ctrl-F and search for the problem filename
  • If needed, click "View diff"
  • Eyeball the diff for any major or minor changes

The (easy) solution

Sometimes the theme file is not radically different and you can get away with updating the @version number.

  • Open up the theme file
  • Look for the @version number in the header (eg. @version 2.1.1) and change to (@version 3.0.0)
  • Save and refresh WC to see if anything is broken or doesn't work.

The (harder) solution

Sometimes you will need to compare the theme file against the version it originated from (eg both are 2.1.1 but you want to know what the previous dev added or removed).

  • Go to www.diffchecker.com
  • Go to the relevant file in Github: https://raw.githubusercontent.com/woocommerce/woocommerce/2.1.1/templates/the-template-file.php
  • Copy this - this is your source. Paste into diffchecker.
  • Copy the content from the corresponding theme file and paste into diffchecker.
  • Run the diff checker and work out what's changed.

If other dramatic changes noticed, you'll need to open the latest copy of the file and copy-paste each line over.

  • Command-click the "View" button
  • Look at the line numbers and reference against the diff, and copy-paste stuff
  • Look for the @version number in the header (eg. @version 2.1.1) and change to (@version 3.0.0)
  • If complex, use an online diff checker tool (diffchecker.com) and paste master & your files in there to see if you missed anything.
  • Save and refresh WC to see if anything is broken or doesn't work.

Always commit your changes!

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment