Skip to content

Instantly share code, notes, and snippets.

Avatar

Stuart Duff stuartduff

View GitHub Profile
@stuartduff
stuartduff / storefront-homepage-all-product-categories.php
Created Apr 26, 2021
Displays all product categoris on the homepage of Storefront
View storefront-homepage-all-product-categories.php
function sd_display_four_home_product_categories( $args ) {
// Displays all product categoris on the homepage of Storefront
$args['limit'] = -1;
// Output
return $args;
}
add_filter( 'storefront_product_categories_args', 'sd_display_four_home_product_categories' );
@stuartduff
stuartduff / wc-remove-bookings-from-price.php
Created Apr 23, 2021
This code snippet will remove the word From: in the WooCommerce Bookings price display
View wc-remove-bookings-from-price.php
function custom_booking_product_price( $price, $product ) {
$target_product_types = array(
'booking'
);
if ( in_array ( $product->product_type, $target_product_types ) ) {
$price = str_replace("From:", "", $price);
return $price;
}
// return normal price
return $price;
@stuartduff
stuartduff / remove-billing-email-field..php
Created Apr 8, 2021
Remove billing email field from WooCommerce
View remove-billing-email-field..php
function custom_override_billing_fields( $fields ) {
unset($fields['billing_email']);
return $fields;
}
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
@stuartduff
stuartduff / remove-add-to-cart-archives.php
Created Apr 5, 2021
Remove Add To Cart Buttons From WooCommerce Product Archives
View remove-add-to-cart-archives.php
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
@stuartduff
stuartduff / wcs-remove-resubscribe.php
Created Feb 24, 2021
Remove resubscribe button for WC Subscriptions
View wcs-remove-resubscribe.php
/**
* 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 Feb 18, 2021
Changes the county field to state/region to separate regions in the UK for brexit.
View wc-billing-fields-uk-brexit-regions.php
/**
* 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 / wc-billing-fields-required.php
Created Dec 15, 2020
Sets all Billing fields on WooCommerce checkout to required
View wc-billing-fields-required.php
/**
* 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 Dec 10, 2020
Change Failed orders in WooCommerce to the order status of Pending
View wc-failed-to-pending-orders.php
/**
* 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');
@stuartduff
stuartduff / move-stripe-payment-request-buttons.php
Created Oct 27, 2020
Move the WooCommerce Stripe payment request butttons.
View move-stripe-payment-request-buttons.php
remove_action( ‘woocommerce_after_add_to_cart_quantity’, array( WC_Stripe_Payment_Request::instance(), ‘display_payment_request_button_html’ ), 1 );
add_action( ‘woocommerce_simple_add_to_cart’, array( WC_Stripe_Payment_Request::instance(), ‘display_payment_request_button_html’ ), 1 );
View processing-to-on-hold-email.php
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 ) {