Skip to content

Instantly share code, notes, and snippets.

View mikejolley's full-sized avatar
💭
I may be slow to respond.

Mike Jolley mikejolley

💭
I may be slow to respond.
View GitHub Profile
@mikejolley
mikejolley / gist:2282666
Last active January 15, 2018 19:58
WooCommerce - Don't allow PO BOX within postcode, address 1 or address 2 fields.
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode( $posted ) {
global $woocommerce;
// Put postcode, address 1 and address 2 into an array
$check_address = array();
$check_address[] = isset( $posted['shipping_postcode'] ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
$check_address[] = isset( $posted['shipping_address_1'] ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$check_address[] = isset( $posted['shipping_address_2'] ) ? $posted['shipping_address_2'] : $posted['billing_address_2'];
@mikejolley
mikejolley / gist:2328155
Created April 7, 2012 11:57
WooCommerce - Custom order number (in 1.5.3+)
add_filter( 'woocommerce_order_number', 'custom_woocommerce_order_number', 1, 2 );
function custom_woocommerce_order_number( $oldnumber, $order ) {
return 'CUSTOMPREFIX' . $order->id;
}
@mikejolley
mikejolley / title.php
Created April 12, 2012 20:05
WooCommerce - Review under the title
<?php
/**
* Single Product Title
*/
?>
<h1 itemprop="name" class="product_title page-title"><?php the_title(); ?></h1>
<?php
global $wpdb, $post;
@mikejolley
mikejolley / gist:2767607
Created May 22, 2012 08:32
WooCommerce - Default shipping SUB-method 1.5.7/1.6+
add_filter( 'woocommerce_shipping_chosen_method', 'custom_shipping_chosen_method', 10, 2 );
function custom_shipping_chosen_method( $chosen_method, $_available_methods ) {
switch ( $_available_methods[0] ) {
case 'table_rate:0-USPS':
$chosen_method = 'table_rate:0-USPS';
break;
case 'table_rate:1-USPS':
$chosen_method = 'table_rate:1-USPS';
break;
@mikejolley
mikejolley / functions.php
Last active June 19, 2023 03:10
WooCommerce - Show quantity inputs for simple products within loops.
<?php
/**
* Code should be placed in your theme functions.php file.
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
@mikejolley
mikejolley / gist:2844797
Created May 31, 2012 17:09
Zeus web server config for WordPress
RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}
# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
@mikejolley
mikejolley / gist:2883308
Created June 6, 2012 17:02
Delete a post type + orphaned term relationships and meta. Replace wp_ with your prefix. Use at own risk ;)
DELETE p FROM wp_posts p WHERE p.post_type = 'product';
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE tr FROM wp_term_relationships tr INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN ( SELECT ID FROM wp_posts );
@mikejolley
mikejolley / gist:2974310
Created June 22, 2012 18:13
WooCommerce - Set default state/country for checkout
/**
* Manipulate default state and countries
*
* As always, code goes in your theme functions.php file
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
return 'XX'; // country code
@mikejolley
mikejolley / gist:3012597
Created June 28, 2012 17:12
WooCommerce - Manipulate the states
/**
* Code goes in functions.php or a custom plugin. Replace XX with the country code your changing.
*/
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['XX'] = array(
'XX1' => 'State 1',
'XX2' => 'State 2'
@mikejolley
mikejolley / gist:3097073
Last active January 18, 2024 17:54
WooCommerce - Unhook/Disable emails
/**
* Code goes in functions.php or a custom plugin.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/