Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 14, 2015 23:18
Add custom field to checkout page
/**
* Add the field to the checkout page
*/
add_action( 'woocommerce_after_order_notes', 'some_custom_checkout_field' );
function some_custom_checkout_field( $checkout ) {
echo '<div id="some_custom_checkout_field"><h2>' . __('My Field Header') . '</h2>';
woocommerce_form_field( 'some_field_name', array(
@ScottDeLuzio
ScottDeLuzio / robots.txt
Created August 14, 2015 23:15
Robots.txt prevent access to WooCommerce add-to-cart links
User-agent: *
Disallow: /*add-to-cart=*
@ScottDeLuzio
ScottDeLuzio / mysql_query
Created August 14, 2015 23:14
MySQL query remove WooCommerce transients
DELETE FROM wp_options
WHERE option_name LIKE '_transient_wc_%' OR option_name LIKE '_transient_timeout_wc_%';
@ScottDeLuzio
ScottDeLuzio / mysql_query
Created August 14, 2015 23:13
MySQL query remove wc_sessions
DELETE FROM wp_options
WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%';
@ScottDeLuzio
ScottDeLuzio / functions.php
Last active August 29, 2015 14:27
Check if product is in cart
<?php
function conditional_checkout_field( $checkout ) {
echo '<div id="conditional_checkout_field">';
$check_in_cart = conditional_product_in_cart(xxxx); //replace xxxx with the product id
// Check if the product is in the cart and show the custom fields if it is
if ($check_in_cart === true ) {
echo '<h2>'.__('My Custom Checkout Field').'</h2>';
@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 14, 2015 23:02
Hook into checkout form
add_action('woocommerce_after_order_notes', 'conditional_checkout_field');