Skip to content

Instantly share code, notes, and snippets.

@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@maxrice
maxrice / wp-login-with-sha1-password.php
Created July 30, 2012 02:43
Allow wordpress login with sha1 password hash in database
<?php
// check if hashed password is SHA1 and update as necessary, see function comments
add_filter( 'check_password', 'check_sha1_password', 10, 4 );
/**
* Check if a user has a SHA1 password hash, allows login if password hashes match, then updates password hash to wp format
*
* Hooks into check_password filter, mostly copied from md5 upgrade function with pluggable.php/wp_check_password
*
* @param string $check
@maxrice
maxrice / wp-jquery.php
Created August 1, 2012 18:47 — forked from chrisguitarguy/wp-jquery.php
Maybe load jQuery from the google cdn
add_action( 'init', 'maybe_load_jquery_from_google', 1 );
function maybe_load_jquery_from_google() {
// do not load in wp-admin
if( is_admin() )
return;
// Load from SSL if necessary
$protocol = is_ssl() ? 'https:' : 'http:';
$url = $protocol . '//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js';
@maxrice
maxrice / resizer.php
Created August 30, 2012 11:59
Resize images to a specific size while maintaining original aspect-ratio via PHP CLI
<?php
// only process image files
$accepted_extensions = array( 'jpg', 'jpeg', 'png' );
// set final size of cropped image
$image_size_width = 892;
$image_size_height = 892;
//only process files in directory that script is in
@maxrice
maxrice / wc-hide-flat-rate-shipping.php
Created September 12, 2012 18:04
Hide default flat rate shipping method when free shipping is available
// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {
@maxrice
maxrice / class-ftp-implicit-ssl-tls.php
Created January 16, 2013 03:11
Basic class to connect to an FTP server with Implicit SSL/TLS and upload a file
<?php
/**
* FTP with Implicit SSL/TLS Class
*
* Simple wrapper for cURL functions to transfer an ASCII file over FTP with implicit SSL/TLS
*
* @category Class
* @author Max Rice
* @since 1.0
*/
<methodCall>
<methodName>
wc.updateOrderStatus
</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>username</name>
add_action( 'woocommerce_init', 'load_my_shipping_class' );
function load_my_shipping_class() {
class My_Shipping_Class extends WC_Shipping_Method {
// foo
}
}
@maxrice
maxrice / gist:6541634
Last active April 23, 2020 18:11
WooCommerce - sort the cart alphabetically by the product's title
<?php
add_action( 'woocommerce_cart_loaded_from_session', function() {
global $woocommerce;
$products_in_cart = array();
foreach ( $woocommerce->cart->cart_contents as $key => $item ) {
$products_in_cart[ $key ] = $item['data']->get_title();
}
@maxrice
maxrice / gist:6553930
Last active December 23, 2015 00:29
Add custom fields to XML for the WooCommerce Customer/Order XML Export Suite
<?php
function add_custom_fields_to_xml( $order_data, $order ) {
$order_data['BillingCompanyID'] = ( isset( $order->order_custom_fields['billing_company_id'][0] ) ) ? $order->order_custom_fields['billing_company_id'][0] : '';
$order_data['BillingCompanyVAT'] = ( isset( $order->order_custom_fields['billing_company_vat'][0] ) ) ? $order->order_custom_fields['billing_company_vat'][0] : '';
return $order_data;
}
add_filter( 'wc_customer_order_xml_export_suite_order_export_order_list_format', 'add_custom_fields_to_xml', 10, 2 );