Skip to content

Instantly share code, notes, and snippets.

@mikejolley
mikejolley / gist:2193064
Created March 25, 2012 11:38
WooCommerce - Store customer IP in order meta
// Code goes in functions.php
add_action( 'woocommerce_checkout_update_order_meta', 'wc_store_user_ip' );
function wc_store_user_ip( $order_id ) {
update_post_meta( $order_id, 'Customer IP', $_SERVER['REMOTE_ADDR'] );
}
@mikejolley
mikejolley / gist:2263203
Last active June 1, 2019 17:50
WooCommerce - Add custom field (in an order) to the order emails
/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');
function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['How did you hear about us?'] = 'hear_about_us';
return $keys;
}
@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 / 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 );
@gregrickaby
gregrickaby / remove-woocommerce-styles-scripts.php
Last active November 26, 2024 23:20
Remove WooCommerce styles and scripts.
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php
/**
* Manage WooCommerce styles and scripts.
*/
function grd_woocommerce_script_cleaner() {
// Remove the generator tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@spivurno
spivurno / gw-gravity-forms-double-confirmation-fields.php
Last active May 18, 2020 02:54
Gravity Wiz // Double Confirmation Fields
<?php
/**
* Gravity Wiz // Gravity Forms // Double Confirmation Fields
*
* Require a field's value to be entered twice to confirm it.
*
* @version 0.2
* @author David Smith <[email protected]>
* @license GPL-2.0+
* @link http://gravitywiz.com/custom-field-confirmation/
@spivurno
spivurno / gw-gravity-forms-inventory.php
Last active November 11, 2020 02:07
Gravity Wiz // Gravity Forms // Better Inventory with Gravity Forms (aka Limit by Sum of Field Values)
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-inventory.php
*/
/**
* Gravity Wiz // Gravity Forms // Better Inventory with Gravity Forms
*
* Implements the concept of "inventory" with Gravity Forms by allowing the specification of a limit determined by the
@kloon
kloon / gist:4228021
Created December 6, 2012 20:25
WooCommerce variations custom field
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'variable_fields_process', 10, 1 );
function variable_fields( $loop, $variation_data ) {
?>
<tr>
@toddmotto
toddmotto / gist:4655457
Created January 28, 2013 13:22
iOS detect
var iOS = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i);
if (!iOS) {
// Run scripts for anything but iOS
}