Skip to content

Instantly share code, notes, and snippets.

View stuartduff's full-sized avatar

Stuart Duff stuartduff

View GitHub Profile
@stuartduff
stuartduff / storefront-custom-homepage-text-section.php
Last active December 12, 2018 11:29
Add a custom text section to the storefront themes homepage template.
function sf_output_custom_text_section() {
echo '<section class="storefront-product-section storefront-product-category">';
echo '<h2 class="section-title">' . __( 'Text Title', 'storefront' ) . '</h2>';
echo '<p>This is some text blurb</p>';
echo '</section>';
@stuartduff
stuartduff / wc-remove-billing-fields-required.php
Last active January 23, 2019 14:41
Removes the required status for all WooCommerce Checkout Billing Fields
/**
* Sets all WooCommerce billing fields to be unrequired.
*/
function wc_unrequire_billing_fields( $fields ) {
$fields['billing_first_name']['required'] = false;
$fields['billing_last_name']['required'] = false;
$fields['billing_company']['required'] = false;
$fields['billing_country']['required'] = false;
$fields['billing_address_1']['required'] = false;
$fields['billing_city']['required'] = false;
@stuartduff
stuartduff / wc-remove-paypal-checkout.php
Created July 3, 2018 12:54
Remove PayPal Standard from displaying at checkout in WooCommerce
/**
* Remove PayPal Standard from displaying at checkout in WooCommerce
*/
function remove_paypal_from_available_payment_gateways( $gateways ) {
unset( $gateways['paypal'] );
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'remove_paypal_from_available_payment_gateways' );
@stuartduff
stuartduff / remove-free-shipping-if-coupon-used.php
Created June 14, 2018 10:26
Remove free shipping in WooCommerce if a coupon is applied at checkout
add_filter( 'woocommerce_shipping_packages', function( $packages ) {
$applied_coupons = WC()->session->get( 'applied_coupons', array() );
if ( ! empty( $applied_coupons ) ) {
$free_shipping_id = 'free_shipping:2';
unset($packages[0]['rates'][ $free_shipping_id ]);
}
return $packages;
} );
@stuartduff
stuartduff / add-fa5-to-wphead.php
Created May 9, 2018 13:29
Add fontawesome 5 CSS to head area of WordPress
function add_fontawesome5_to_head() {
echo '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">';
}
add_action( 'wp_head', 'add_fontawesome5_to_head' );
@stuartduff
stuartduff / wooslider-blacklist-jetpack-lazy-load.php
Last active May 8, 2018 16:33
WooSlider blacklist Jetpack lazy load images for slides
function wooslider_lazy_exclude( $blacklisted_classes ) {
$blacklisted_classes = array(
'skip-lazy',
'gazette-featured-content-thumbnail',
'post-image',
);
return $blacklisted_classes;
@stuartduff
stuartduff / remove-storefront-handheld-footer-links.php
Last active April 3, 2018 12:42
Remove the WooCommerce Storefront theme handlheld footer bar links
@stuartduff
stuartduff / gist:075bcb18d7ee836f17c86dc341e3340b
Created April 3, 2018 12:34
Remove cart from storefront mobile sticky footer
add_filter( 'storefront_handheld_footer_bar_links', 'remove_mobile_links' );
function remove_mobile_links( $links ) {
unset( $links['cart'] );
return $links;
}
@stuartduff
stuartduff / wc-set-single-product-image-cropping-sizes.php
Last active April 3, 2018 10:32
Set cropping sizes for WooCommerce single product images.
add_filter( 'woocommerce_get_image_size_single', 'custom_wc_product_img_size' );
add_filter( 'woocommerce_get_image_size_shop_single', 'custom_wc_product_img_size' );
add_filter( 'woocommerce_get_image_size_woocommerce_single', 'custom_wc_product_img_size' );
function custom_wc_product_img_size() {
$size = array(
'width' => 800,
'height' => 800,
'crop' => 1,
);
@stuartduff
stuartduff / wc-set-image-sizes.php
Last active February 16, 2018 11:42
WooCommerce set images sizes
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 300,
'single_image_width' => 600,
) );