Skip to content

Instantly share code, notes, and snippets.

View conschneider's full-sized avatar
🐼
Relax. Nothing is under control.

Con Schneider conschneider

🐼
Relax. Nothing is under control.
View GitHub Profile
@conschneider
conschneider / Query
Created July 9, 2019 08:25 — forked from lukecav/Query
MySQL script to get all WooCommerce orders including metadata
select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_billing_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_1,
max( CASE WHEN pm.meta_key = '_billing_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_2,
max( CASE WHEN pm.meta_key = '_billing_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_city,
max( CASE WHEN pm.meta_key = '_billing_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_state,
@conschneider
conschneider / Enable WooCommerce image sizes in Customizer.php
Created June 16, 2019 10:15
This enables custom image sizes for WooCommerce in the Customizer even when the theme has declared the images sizes. This works with the Storefront theme.
<?php
/*
Plugin Name: Custom Image Sizes for WooCommerce
Plugin URI: https://themebynumbers.com/
Description: Let's you customize WooCommerce product image sizes from the Customizer
Version: 0.1
Author: Mikey Arce
Author URI: https://themebynumbers.com
Text Domain: custom_image_sizes_for_wc
Domain Path: /languages
@conschneider
conschneider / wp502woo.php
Last active December 20, 2018 09:40
WooCommerce WordPress 5.0.2 orders tab fix - fixes the empty all orders tab in WooCommerce after updating to WordPress 5.0.2
if(version_compare(get_option( 'woocommerce_version' ),"3.5.2","<=") && version_compare(get_bloginfo( 'version' ),"5.0.2","=") ){
function fix_request_query_args_for_woocommerce( $query_args ) {
if ( isset( $query_args['post_status'] ) && empty( $query_args['post_status'] ) ) {
unset( $query_args['post_status'] );
}
return $query_args;
}
add_filter( 'request', 'fix_request_query_args_for_woocommerce', 1, 1 );
}
@conschneider
conschneider / wp-only-super-admin-dashboard-access.php
Created October 18, 2018 13:30
Only allows super admins into the WordPress dashboard.
function cs_super_admin_access(){
if ( ! defined( 'DOING_AJAX' ) && ! is_super_admin () ) {
wp_redirect( home_url() );
die();
}
}
add_action( 'admin_init', 'cs_super_admin_access', 1 );
@conschneider
conschneider / woo-require-state-in-checkout-always.php
Last active October 23, 2018 08:34
Makes the state field in WooCommerce checkout always required.
/* https://www.mootpoint.org/blog/woocommerce-make-uk-county-field-required/ for an excellent description on why this filter. */
add_filter( 'woocommerce_get_country_locale', 'mp_change_locale_field_defaults');
function mp_change_locale_field_defaults($countries) {
//swap 'RO' for your country ID.
$countries['RO']['state']['required'] = true;
//set custom field label
$countries['RO']['state']['label'] = '';
@conschneider
conschneider / woocommerce-show-notice-when-backorder.php
Last active April 11, 2020 21:02
WooCommerce add notices for when backorders are (not) allowed.
//output with add to cart button on product detail page
add_action( 'woocommerce_after_add_to_cart_form', 'custom_notice_for_backorders_allowed' );
function custom_notice_for_backorders_allowed()
{
//instantinate product object
global $product;
//check if backorders are allowed
if ( $product->backorders_allowed() )
@conschneider
conschneider / woocommerce-pdf-voucher-custom-filename.php
Created November 5, 2017 13:33
Change WooCommerce PDF Voucher string to custom name
<?php //only copy if needed
//filter documented at: https://docs.woocommerce.com/document/woocommerce-pdf-product-vouchers-developer-documentation/#wc_pdf_product_vouchers_voucher_filename
add_filter('wc_pdf_product_vouchers_voucher_filename', 'cs_my_own_filename');
function cs_my_own_filename ($filename) {
// This is how the variable is defined: $filename = 'voucher-' . sanitize_file_name( $this->get_voucher_number() ) . '.' . $type;
// Note: $type may be defined as string. Default $type = 'pdf';
// Note: Do not use this filter to change the number. There are other filters for that.
@conschneider
conschneider / wp-check-if-post-has-custom-taxonomy
Created September 27, 2017 18:30
WordPress check if post has custom taxonomy
<?php
// use of function has_term( 'slug', 'taxonomy_name', $post->ID );
// taxonomy_name for example: Visibility
// slug for example: visible
// $post->ID = current post
$terms = has_term( 'intern', 'artikel_typ', $post->ID );
if($terms)
{
@conschneider
conschneider / wp_mail.md
Created August 3, 2017 19:17 — forked from johnbillion/wp_mail.md
WordPress Emails

WordPress Emails

This document lists all the situations where WordPress sends an email, along with how to filter or disable each email.

This is accurate as of WordPress 4.8, and includes some upcoming changes in WordPress 4.9.

There are a few TODOs left. Please bear with me.

@conschneider
conschneider / update-mysql56.sh
Created July 18, 2017 09:00 — forked from technosailor/update-mysql56.sh
Updates VVV MySQL 5.5 to 5.6 -- Ubuntu 14.04
#!/bin/bash
# Usage: ./update-mysql56.sh
# Backup of all databases... JUST IN CASE
mysqldump --all-databases --single-transaction --events --user=root --password > ~/all_database_backup.sql
# Remove MySQL 5.5
sudo apt-get remove mysql-server
sudo apt-get autoremove