Skip to content

Instantly share code, notes, and snippets.

View stuartduff's full-sized avatar

Stuart Duff stuartduff

View GitHub Profile
@stuartduff
stuartduff / remove-add-to-cart-archives.php
Created April 5, 2021 10:53
Remove Add To Cart Buttons From WooCommerce Product Archives
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
@stuartduff
stuartduff / wcs-remove-resubscribe.php
Created February 24, 2021 11:48
Remove resubscribe button for WC Subscriptions
/**
* Remove the "Change Payment Method" button from the My Subscriptions table.
*
* This isn't actually necessary because @see eg_subscription_payment_method_cannot_be_changed()
* will prevent the button being displayed, however, it is included here as an example of how to
* remove just the button but allow the change payment method process.
*/
function eg_remove_my_subscriptions_button( $actions, $subscription ) {
foreach ( $actions as $action_key => $action ) {
@stuartduff
stuartduff / wc-billing-fields-uk-brexit-regions.php
Last active February 18, 2021 18:02
Changes the county field to state/region to separate regions in the UK for brexit.
/**
* Changes the county field to state/region to separate regions in the UK for brexit.
* This can be used to specify specific shipping zones for UK regions, like exluding Northern Ireland from UK shipping.
*/
function custom_woocommerce_uk_states_brexit( $states ) {
$states['GB'] = array(
'ENG' => 'England',
'SCO' => 'Scotland',
@stuartduff
stuartduff / storefront-powerpack-custom-header-element.php
Created November 1, 2017 15:33
Add a custom text element to the header configurator of Storefront Powerpack
// Adds the text element to the powerpack header components
function sp_header_components_custom_text( $components ) {
$components['text'] = array(
'title' => __( 'Custom Text', 'storefront-powerpack' ),
'hook' => 'sp_header_custom_text_output'
);
return $components;
}
add_filter( 'sp_header_components', 'sp_header_components_custom_text' );
@stuartduff
stuartduff / move-storefront-product-sharing-buttons-below-descripton.css
Last active January 5, 2021 02:24
Move storefront product sharing icons below the description on the WooCommerce product page.
@media screen and (min-width: 768px) {
.storefront-product-sharing {
padding: 0 0 2.618em 0 !important;
border-top: 0 !important;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
margin-bottom: 2.618em;
}
}
@stuartduff
stuartduff / remove-storefront-search-box-header.php
Created January 5, 2016 13:26
Remove the search box from the header of WooThemes Storefront theme
function remove_sf_actions() {
remove_action( 'storefront_header', 'storefront_product_search', 40 );
}
add_action( 'init', 'remove_sf_actions' );
@stuartduff
stuartduff / wc-billing-fields-required.php
Created December 15, 2020 09:23
Sets all Billing fields on WooCommerce checkout to required
/**
* Sets all WooCommerce billing fields to be required.
*/
function wc_require_billing_fields( $fields ) {
$fields['billing_first_name']['required'] = true;
$fields['billing_last_name']['required'] = true;
$fields['billing_company']['required'] = true;
$fields['billing_country']['required'] = true;
$fields['billing_address_1']['required'] = true;
$fields['billing_city']['required'] = true;
@stuartduff
stuartduff / wc-failed-to-pending-orders.php
Created December 10, 2020 14:20
Change Failed orders in WooCommerce to the order status of Pending
/**
* Set failed orders to pending payment.
*/
function wc_failed_to_pending( $order_id ){
$order = new WC_Order( $order_id );
$order->update_status( 'pending' );
}
add_action( 'woocommerce_order_status_failed', 'wc_failed_to_pending');
function add_another_email_action( $array ) {
$array[]='woocommerce_order_status_processing_to_on-hold';
return $array;
}
add_filter( 'woocommerce_email_actions', 'add_another_email_action' );
function hook_another_email_on_hold( $email_class ) {
@stuartduff
stuartduff / gist:5805532
Created June 18, 2013 13:51
Change the word Products in the WooCommerce breadcrumb trail
add_filter( 'woo_breadcrumbs_trail', 'woo_custom_filter_breadcrumbs_trail', 10 );
function woo_custom_filter_breadcrumbs_trail ( $trail ) {
foreach ( $trail as $k => $v ) {
if ( strtolower( strip_tags( $v ) ) == 'products' ) {
$trail[$k] = 'Photos';
break;
}
}
return $trail;
} // End woo_custom_filter_breadcrumbs_trail()