Skip to content

Instantly share code, notes, and snippets.

View BFTrick's full-sized avatar

Patrick Rauland BFTrick

View GitHub Profile
@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
@BFTrick
BFTrick / functions.php
Created May 26, 2016 15:05
WooCommerce add an Empty Cart button
<?php
// check for empty-cart get param to clear the cart
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
@BFTrick
BFTrick / functions.php
Created May 24, 2016 20:12
Customize the sort by drop down in WooCommerce
<?php
function patricks_woocommerce_catalog_orderby( $orderby ) {
// Add "Sort by date: oldest to newest" to the menu
// We still need to add the functionality that actually does the sorting
$orderby['oldest_to_recent'] = __( 'Sort by date: oldest to newest', 'woocommerce' );
// Change the default "Sort by newness" to "Sort by date: newest to oldest"
$orderby["date"] = __('Sort by date: newest to oldest', 'woocommerce');
// Remove price & price-desc
@BFTrick
BFTrick / functions.php
Created May 24, 2016 20:04
WooCommerce hide the sort by option.
<?php
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
@BFTrick
BFTrick / woocommerce-modify-orderby.php
Created May 24, 2016 19:55
Add new option to WooCommerce to sort oldest to newest
<?php
// Add "Sort by date: oldest to newest" to the menu
// We still need to add the functionality that actually does the sorting
// Original credit to Remi Corson: http://www.remicorson.com/woocommerce-sort-products-from-oldest-to-most-recent/
function patricks_woocommerce_catalog_orderby( $sortby ) {
$sortby['oldest_to_recent'] = __( 'Sort by date: oldest to newest', 'woocommerce' );
return $sortby;
}
add_filter( 'woocommerce_catalog_orderby', 'patricks_woocommerce_catalog_orderby', 20 );
@BFTrick
BFTrick / woocommerce-modify-orderby.php
Last active October 19, 2022 10:16
A function that modifies the default WooCommerce orderby dropdown. You can put this snippet in your functions.php file.
<?php
// Modify the default WooCommerce orderby dropdown
//
// Options: menu_order, popularity, rating, date, price, price-desc
// In this example I'm changing the default "Sort by newness" to "Sort by date: newest to oldest"
function patricks_woocommerce_catalog_orderby( $orderby ) {
$orderby["date"] = __('Sort by date: newest to oldest', 'woocommerce');
return $orderby;
}
add_filter( "woocommerce_catalog_orderby", "patricks_woocommerce_catalog_orderby", 20 );
@BFTrick
BFTrick / functions.php
Created May 18, 2016 11:32
Always show shipping fields in WooCommerce checkout
<?php
add_filter( 'woocommerce_cart_needs_shipping', '__return_true' );
@BFTrick
BFTrick / style.css
Created May 16, 2016 17:09
Adding white space around Font Awesome Icon on WooCommerce Add to Cart button
.single_add_to_cart_button.fa:before {
padding-right: 10px;
}