Skip to content

Instantly share code, notes, and snippets.

View TimBHowe's full-sized avatar

Tim Howe TimBHowe

View GitHub Profile
@bekarice
bekarice / wc-disable-product-repeat-purchase.php
Last active March 9, 2020 07:13
Disables Repeat Purchase for a particular WooCommerce product
<?php // only copy if needed!
/**
* Disables repeat purchase for the product
*
* @param bool $purchasable true if product can be purchased
* @param \WC_Product $product the WooCommerce product
* @return bool $purchasable the updated is_purchasable check
*/
function sv_disable_repeat_purchase( $purchasable, $product ) {
@gbyat
gbyat / custom-fields-for-variations.php
Last active July 28, 2020 22:54
WooCommerce Custom Fields for Variations
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//Save variation fields
add_action( 'woocommerce_save_product_variation', 'save_variable_fields', 10, 2 );
function variable_fields( $loop, $variation_data, $variation ) {
// Text Field
$text_field = get_post_meta( $variation->ID, '_text_field', true );
@jlavoie13
jlavoie13 / template-h1-tag.php
Last active December 16, 2015 18:07
Tuckaway H1
<?php
/**
* H1 Tag Template
*
* This is a tuckaway H1 tag for SEO purposes.
*/
// Set Variables
$h1_field = 'h1_tag'; // the field name defined in acf
$default_posttype = 'News'; // ex. Posts or News
@kloon
kloon / functions.php
Created March 28, 2014 08:58
WooCommerce 2.1 Add confirm password field on My Account register form
<?php
// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts.
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) );
}
@BFTrick
BFTrick / woocommerce-check-terms.php
Last active February 12, 2024 12:02
Make the WooCommerce Terms & Conditions checkbox checked by default
<?php
/**
* Plugin Name: WooCommerce Check Terms & Conditions
* Plugin URI: https://gist.github.com/BFTrick/7789974
* Description: Make the Terms & Conditions checkbox checked by default
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@mikejolley
mikejolley / gist:6713608
Last active September 5, 2018 10:59
WooCommerce Shipping Method Skeleton Plugin
<?php
/*
Plugin Name: Your Shipping plugin
Plugin URI: http://woothemes.com/woocommerce
Description: Your shipping method plugin
Version: 1.0.0
Author: WooThemes
Author URI: http://woothemes.com
*/
@justinhillsjohnson
justinhillsjohnson / gist:5503121
Created May 2, 2013 15:43
code-review-checklist
General
1. Site uses a cache buster for expiring .js, .css, and images
2. JavaScript and CSS is minified and concatenated into logical groupings
3. Images have been optimized by ImageOptim (http://imageoptim.com/)
Markup
1. Code does not contain inline JavaScript event listeners
@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'];