Skip to content

Instantly share code, notes, and snippets.

View BFTrick's full-sized avatar

Patrick Rauland BFTrick

View GitHub Profile
<?php
/*
Plugin Name: Pixel Perfect Webinar Changes
Description: The changes for the Pixel Perfect Webinar
Version: 1.0.0
Author: Patrick Rauland
Author URI: https://speakinginbytes.com
*/
@BFTrick
BFTrick / heap.php
Last active November 4, 2016 14:59
Load Heap Analytics
<?php
/*
* Plugin Name: Heap Analytics
* Plugin URI: https://gist.github.com/BFTrick/bb3b3b0e0497e8adecfa00e3c8e1b33d
* Description: Send all site data to Heap Analytics
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com
* Version: 1.0
*/
@BFTrick
BFTrick / functions.php
Last active July 19, 2017 18:58
WooCommerce change the number of products per row. You still have to write CSS so each of the products fit in there.
<?php
// change the number of products per row
add_filter( 'loop_shop_columns', 'patricks_loop_columns', 20 );
function patricks_loop_columns() {
return 5; // the number of products per row
}
// you still need to add CSS to make it look right. In Storefront you can add this to your style.css file.
// @media (min-width:768px){
// .products .product {
@BFTrick
BFTrick / functions.php
Last active July 26, 2016 20:39
Show 20 products per page in WooCommerce
<?php
// Display 25 products per page. Goes in your theme's functions.php
// Credit: https://gist.github.com/jameskoster/1601682
add_filter( 'loop_shop_per_page', 'patricks_products_per_page', 20 );
function patricks_products_per_page( $num_products ) {
return 20;
}
@BFTrick
BFTrick / functions.php
Created June 1, 2016 16:46
Sort WooCommerce shipping methods by cost
<?php
// credit: ChromeOrange - https://gist.github.com/ChromeOrange/10013862
add_filter( 'woocommerce_package_rates' , 'patricks_sort_woocommerce_available_shipping_methods', 10, 2 );
function patricks_sort_woocommerce_available_shipping_methods( $rates, $package ) {
// if there are no rates don't do anything
if ( ! $rates ) {
return;
}
@BFTrick
BFTrick / functions.php
Last active May 31, 2016 23:52
Redirect to a specific product category after a product is added to the cart
<?php
add_filter( 'woocommerce_add_to_cart_redirect', 'patricks_custom_cart_redirect' );
function patricks_custom_cart_redirect() {
// our prodcut category ID
$product_cat_id = 10; // replace this number with your category ID
// redirect to the page
return get_term_link( $product_cat_id, 'product_cat' );
}
@BFTrick
BFTrick / functions.php
Created May 31, 2016 23:18
Redirect add to cart action to Shop page
<?php
// credit: WooThemes https://gist.github.com/woogist/6fd2d358bb2e51a25ac5
add_filter( 'woocommerce_add_to_cart_redirect', 'patricks_custom_cart_redirect' );
function patricks_custom_cart_redirect() {
return get_permalink( wc_get_page_id( 'shop' ) );
}
@BFTrick
BFTrick / style.css
Last active January 29, 2019 17:45
Hide unnecessary elements on the woocommerce checkout page - compatible with the Storefront theme
.woocommerce-checkout .storefront-primary-navigation,
.woocommerce-checkout .site-search,
.woocommerce-checkout .header-widget-region,
.woocommerce-checkout .footer-widgets {
display: none;
}
@BFTrick
BFTrick / functions.php
Created May 26, 2016 15:19
Add a "How did you hear about us" field in WooCommerce
<?php
// Filter the checkout fields
add_filter( 'woocommerce_checkout_fields', 'patricks_woocommerce_checkout_fields' );
// add a "how did you hear about us" field - $fields is passed via the filter
function patricks_woocommerce_checkout_fields( $fields ) {
// add the field
$fields['order']['hear_about_us'] = array(
'type' => 'select',
'class' => array( 'form-row-wide' ),
@BFTrick
BFTrick / functions.php
Created May 26, 2016 15:09
Remove the Phone Number field in the WooCommerce checkout
<?php
// Filter the checkout fields
add_filter( 'woocommerce_checkout_fields', 'patricks_woocommerce_checkout_fields' );
// Remove the billing phone - $fields is passed via the filter
function patricks_woocommerce_checkout_fields( $fields ) {
// remove the phone field
unset($fields['billing']['billing_phone']);
// make the billing email field fill up the entire space