Skip to content

Instantly share code, notes, and snippets.

View TimBHowe's full-sized avatar

Tim Howe TimBHowe

View GitHub Profile
@TimBHowe
TimBHowe / wc_product_price_audit.sql
Created January 23, 2024 15:11
Return all the WooCommerce product and product variation prices set.
SELECT wp_posts.ID, wp_postmeta.meta_value AS sku, wp_posts.post_title AS title, wp_postmeta2.meta_value AS price FROM wp_posts
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_sku' )
LEFT JOIN wp_postmeta AS wp_postmeta2 ON (wp_posts.ID = wp_postmeta2.post_id AND wp_postmeta2.meta_key = '_price' )
WHERE wp_posts.post_type = 'product'
OR wp_posts.post_type = 'product_variation'
@TimBHowe
TimBHowe / wc_product_image_audit.sql
Created January 22, 2024 21:51
Run a query to fine all WooCommerce products feature image and product gallery image IDs. Any that return Null are missing.
SELECT wp_posts.ID, wp_postmeta.meta_value AS sku, wp_posts.post_title AS title, wp_postmeta2.meta_value AS image, wp_postmeta3.meta_value AS gallery FROM wp_posts
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_sku' )
LEFT JOIN wp_postmeta AS wp_postmeta2 ON (wp_posts.ID = wp_postmeta2.post_id AND wp_postmeta2.meta_key = '_thumbnail_id' )
LEFT JOIN wp_postmeta AS wp_postmeta3 ON (wp_posts.ID = wp_postmeta3.post_id AND wp_postmeta3.meta_key = '_product_image_gallery' )
WHERE wp_posts.post_type = 'product'
@TimBHowe
TimBHowe / Mailchimp.js
Last active April 15, 2024 12:44
Mailchimp Popup Tracking
<script id="mcjs">
!function(c,h,i,m,p){m = c.createElement(h), p = c.getElementsByTagName(h)[0], m.async = 1, m.src = i, p.parentNode.insertBefore(m, p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/XXXXX/XXXXX.js");
window.dataLayer = window.dataLayer || [];
var mailchimpObserver = new MutationObserver(function(mutations_list) {
mutations_list.forEach(function (mutation) {
mutation.addedNodes.forEach(function (added_node) {
if (added_node.id == 'PopupSignupForm_0') {
window.dataLayer.push({ event: 'mailchimp_popup_shown' });
document.querySelector('#PopupSignupForm_0 div.mc-modal iframe').contentDocument.querySelector('form').addEventListener('submit', function (event) {
@TimBHowe
TimBHowe / functions.php
Created July 31, 2023 14:29
Add 'rel="next"' and 'rel="prev"' attribute to the next and previous links in the paginate_links function in WordPress.
<?php
/**
* Alter the pagination next and prev links to have rel.
*
* @param string $r HTML output.
* @param array $args An array of arguments. See paginate_links() for information on accepted arguments.
*
* @return sting - The HTML output of the pagination.
*/
function scaffolding_add_rel_pagination( $r, $args ) {
@TimBHowe
TimBHowe / WordPressExportNavMenuItems.sql
Created March 22, 2022 21:14
A series of queries to allow you to export the nav_menu_item post type and related data.
SELECT * FROM `wp_posts` WHERE post_type = 'nav_menu_item';
SELECT * FROM `wp_postmeta` WHERE post_id IN (SELECT ID FROM `wp_posts` WHERE post_type = 'nav_menu_item');
SELECT * FROM `wp_term_relationships` WHERE object_id IN(SELECT ID FROM `wp_posts` WHERE post_type = 'nav_menu_item');
SELECT * FROM `wp_term_taxonomy` WHERE term_taxonomy_id IN ( SELECT term_taxonomy_id FROM `wp_term_relationships` WHERE object_id IN(SELECT ID FROM `wp_posts` WHERE post_type = 'nav_menu_item'));
SELECT * FROM `wp_terms` WHERE term_id IN (SELECT term_id FROM `wp_term_taxonomy` WHERE term_taxonomy_id IN ( SELECT term_taxonomy_id FROM `wp_term_relationships` WHERE object_id IN(SELECT ID FROM `wp_posts` WHERE post_type = 'nav_menu_item')));
@TimBHowe
TimBHowe / ClearWooData.sql
Created January 12, 2022 16:49
This is a series of SQL commands, done for Maridadb, to remove all customers, orders, subscriptions and order notes. Please read and review comments and use at your own risk.
#--- Remove all users, except Admins and Shop_Managers ---
#--Create a temp table based on the one we want to clear.
CREATE OR REPLACE TABLE `temp_usermeta` LIKE `wp_usermeta`;
#--Insert the data we want to keep.
INSERT INTO `temp_usermeta` SELECT * FROM `wp_usermeta` WHERE user_id IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%shop_manager%' OR meta_value LIKE '%administrator%' );
#--Drop the table.
DROP TABLE `wp_usermeta`;
#--Rename to temp table to replace the dropped table.
RENAME TABLE `temp_usermeta` TO `wp_usermeta`;
@TimBHowe
TimBHowe / .pa11yci.js
Last active November 17, 2020 00:01
A sample Pa11y CI config JavaScript file with all available options with their default settings and notes.
/**
* This is a sample Pa11y CI config JavaScript file with all available options with their default settings and notes.
*
* By default, Pa11y CI looks for a config file in the current working directory, named .pa11yci.JSON file.
* You can use the --config command line argument to specify this JavaScript file.
*
* The purpose of this file is to provide an example configuration file users and experiment with in altering the default settings.
*
* Resources:
* https://github.com/pa11y/pa11y-ci#configuration
@TimBHowe
TimBHowe / fix-missingnames.sql
Created April 29, 2020 19:29
Update a WordPress user account first_name and last_name if it is missing with their WooCommerce billing_first_name and billing_last_name if available.
/* Get all the users missing a first_name. */
SELECT * FROM wp_usermeta AS A
WHERE A.meta_key = 'first_name'
AND A.meta_value = '';
/* Updated to first_name to their billing_first_name if available. */
UPDATE wp_usermeta AS A
JOIN ( SELECT user_id, meta_value FROM `wp_usermeta` WHERE wp_usermeta.meta_key = 'billing_first_name' AND wp_usermeta.meta_value <> '') AS B
ON A.user_id = B.user_id
SET A.meta_value = B.meta_value
@TimBHowe
TimBHowe / function.php
Last active April 14, 2020 14:17
A custom function to have all users login using the WooCommerce My Account page if set
<?php
/**
* Update the Login URL to the WooCommerce My Account Page.
*
* @param string $login_url The login URL. Not HTML-encoded.
* @param string $redirect The path to redirect to on login, if supplied.
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
*
* @return string The login URL. Not HTML-encoded.
*/
@TimBHowe
TimBHowe / functions.php
Created May 2, 2018 17:35
BuddyPress version 2.9.4: Auto verify new emails when users update them in their profiles.
<?php
/**
* Auto verify user email changes.
*
* @return void
*/
function custombp_auto_verify_email_change() {
// Double check this is happening on the settings page.
check_admin_referer('bp_settings_general');