Category Archives: programming

Show SKU in cart and checkout [WooCommerce]

Recently I have been setting up a quote only WooCommerce site. Specifically, the site needs to have SKUs listed and quantity info but not pricing. Here is a method to get SKUs listed throughout the cart/checkout pages: Step 1. Setup child theme Step 2. Copy the templates from /plugins/woocommerce/templates/cart/cart.php and /plugins/woocommerce/templates/checkout/review-order.php to your child theme folder, with the result being similar to this: Step 3. To add SKU to Cart and Checkout (Order Review) Edit your cart.php template, where appropriate add: <?php echo

Online PHP code editors

Here are some rather interesting PHP code editors that run entirely online. They can be particularly helpful if you need to be able to develop from any machine anywhere (as long as you have an internet connection). 🙂 PHP Code Editorhttp://edit.orgapage.de/PHP Code Editor is a web based interface to edit your code. This way you can work on your project now matter where in the world you are, or on wich computer you are sitting at. PHP Code Editor works…

Order SQL query manually when numeric string representation is out of order

In some instances, doing a straight ORDER BY ASC (OR DESC) does not work as one might want: 0-50 101-200 201-300 301-400 401-500 501-600 51-100 601+ That is not how humans do it 😉 A way to get around this, is to add a new column and put in an ordering value, for instance: 1. 0-50 2. 51-100 3. 101-200 4. 201-300 5. 301-400 6. 401-500 7. 501-600 8. 601+ Now that is much better 🙂 Here is a real

SQL Server: list all user defined functions in a database

Recently I inherited a database project where many of the functions were not listed nor documented. Thankfully, with the help of the always useful stackoverflow, I was able to find the following snippet for displaying all user functions: select name, definition, type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id=o.object_id where type_desc like ‘%function%’ via sql server – SQL list of all the user defined functions in a database – Stack Overflow. Very cool! 🙂

Format SQL code

I have been writing copious quantities of SQL lately. Some of the queries are getting really long. When I am working with Navicat it has a nice ‘SQL beautify’ feature that takes messy SQL and makes it nice and tidy. 🙂 While that features is great when using Navicat for SQL editing, sometimes I need to workdirectly with SQL Server 2008 there is no comparable feature built into Microsoft’s SQL pane. 🙁 Thankfully, with a quick copy/paste there is an online tool

Select top 2 rows from records, grouped/partitioned by Unique ID

The Problem: A client needed a query that selected the two most recent tour dates for each user ID. This is an easy task for a single user ID because specifying the user ID and an ORDER BY tour_date DESC with a LIMIT 2 clause would get the dates needed. However, when there are a lot of users it gets harder. For a single date, the MAX function works great but in our instance it will not work because we

Replace () / . characters in phone numbers with dashes (MySQL database)

If you have a MySQL database containing phone number records in varying formats, you may want to standardize them. New records can easily be handled by checking data entry against your desired format (via JS or whatever method you like). However, existing records must be dealt with. That is where an UPDATE statement combined some handy MySQL functions can assist us: // Replace forward slash with dash UPDATE db_phonenumbers SET phone_field = REPLACE(phone_field, ‘/’, ‘-‘) // Replace close parenthesis with

Data truncated for column ‘status’ at row 1 [SOLVED]

Recently I encountered the following error: Data truncated for column ‘status’ at row 1 This was specifically in a PHP based web hotel/reservations app that uses MySQL for the database backend. When trying to add a new dropdown option value of ‘departed’, the form submission would always fail with the aforementioned error. Thankfully, the solution was easy once I checked the table/field definitions. The column ‘status’ was of type enum and thus needed to have the ‘departed’ value specifically enumerated in

Page 1 of 212