Skip to content

Instantly share code, notes, and snippets.

View TimBHowe's full-sized avatar

Tim Howe TimBHowe

View GitHub Profile
@TimBHowe
TimBHowe / facebook-for-woocommerce-overrides.php
Created January 31, 2018 13:53
Include this file or add this function to the functions.php file to fire the Facebook Pixel 'AddToCart' event on the 'woocommerce_after_cart' action.
<?php
// Add function to fix some for the event tracking issues from the facebook for WooCommerce 1.7.5 update.
add_action( 'woocommerce_init', 'wc_facebook_tracking_fixes' );
function wc_facebook_tracking_fixes(){
// Get the facebook integration class.
$facebook = WooCommerce::instance()->integrations->get_integrations()['facebookcommerce'];
// Add add to cart event tracking to allow for WooCommerce redirect to cart after adding product.
add_action('woocommerce_after_cart', array($facebook->events_tracker, 'inject_add_to_cart_event'));
}
@TimBHowe
TimBHowe / woocommerce-override.php
Created October 18, 2017 17:46
Add a filter the the WooCommerce `wc_reduce_stock_levels` function to not reduce the stock if more then what is in stock is ordered.
<?php
/**
* Do not reduce stock if more then what is instock is ordered as all items will be back-ordered/made to order/shipped together, and someone else can have the item instock shipped immediately.
* TODO: Should probably check if the item allows backordering.
*/
function wccustom_alter_order_item_quantity( $item_qty_ordered, $order, $item ) {
// Get the product object from the order item object.
$product = $item->get_product();
// Some products (variations) can have their stock managed by their parent. Get the correct ID and then product object.
$product_id_with_stock = $product->get_stock_managed_by_id();
@TimBHowe
TimBHowe / functions.php
Last active August 2, 2017 05:29
WooCommerce - Add custom post_meta data to the order REST API response.
<?php
/**
* Hook into order API response to add custom field data.
*
* @param $order_data array
* @param $order WC_Order
* @param $fields array
* @param $server array
*
@TimBHowe
TimBHowe / functions.php
Last active January 9, 2017 23:51
Contact Form 7 - Make sure the emails in 2 different fields don't match.
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
function custom_email_confirmation_validation_filter( $result, $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( 'your-email' == $tag->name ) {
$your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
$manager_email = isset( $_POST['manager-email'] ) ? trim( $_POST['manager-email'] ) : '';
if ( $your_email == $manager_email ) {
$result->invalidate( $tag, "Your email can NOT match your manager's email." );
@TimBHowe
TimBHowe / functions.php
Created March 23, 2016 19:30
Add post visibility to the lost of location options to ACF. Allowing you to add field to posts based on if it is public, password protected or privet.
<?php
// Add a custom rule type to ACF.
function acf_location_rules_types( $choices ) {
$choices['Post']['post_visibility'] = 'Post Visibility';
return $choices;
}
add_filter('acf/location/rule_types', 'acf_location_rules_types');
@TimBHowe
TimBHowe / functions.php
Last active March 10, 2016 21:34
Reduce or remove WooCommerce 2.5 minimum password strength requirement for creating a user account. Warning: Use at your own risk.
<?php
/**
*Reduce the strength requirement on the woocommerce password.
*
* Strength Settings
* 3 = Strong (default)
* 2 = Medium
* 1 = Weak
* 0 = Very Weak / Anything
*/
@TimBHowe
TimBHowe / functions.php
Created March 8, 2016 17:54
Forcibly remove the tax line item and calculation from the cart. (suggest just using the GEO setting in WooCommerce)
<?php
// Remove the Tax Line item from the cart.
function wc_remove_cart_tax_totals( $tax_totals, $instance ) {
if( is_cart() ) {
$tax_totals = array();
}
return $tax_totals;
}
@TimBHowe
TimBHowe / function.php
Last active October 29, 2015 13:04
Parse through wordpress post content and update the image source URLs to lowercase
<?php
//http://wordpress.stackexchange.com/questions/104605/update-image-path-with-words-starting-uppercase-to-lowercase-chars
//make located image source lowercase
function replace_cb($matches) {
if (!empty($matches[1])) {
return 'src="'.strtolower($matches[1]).'"';
} else {
return $matches[0];
}
}
@TimBHowe
TimBHowe / woocommerce-variation-grid-add-cart.php
Last active September 27, 2021 18:24
Include this in your theme to allow WooCommerce variable products to be displayed in a grid format with each variation having there own quantity and add to cart button, rather then the drop-down options. This should be include in your themes function file.
<?php
/**
* Woocommerce Custom Variation Output
*
* The following function allow for the theme to display product variations in a grid format.
* This code could be moved to a plugin but is in the theme function file as it used the
* themes grid system.
*
* @package WooGrid
* @since WooGrid 1.2
@TimBHowe
TimBHowe / sql-delete-wp-users
Last active August 29, 2015 14:20
How to Delete Users With SQL Queries
--If you want to remove WordPress user(s) and all their data here are SQL queries you should run over your database (just replace %USERS IDs% with ids of users need to be deleted. - http://www.loneshooter.com/wordpress-how-to-delete-users-with-sql-queries/ --
-- Deletes any comments from specific user(s)
DELETE FROM wp_comments WHERE user_id IN (%USERS IDs%);
-- Deletes post meta for specific user(s)
DELETE t1 FROM wp_postmeta t1
LEFT JOIN wp_posts t2 ON t1. post_id = t2.ID
WHERE post_author IN (%USERS IDs%);