Skip to content

Instantly share code, notes, and snippets.

@RiaanKnoetze
RiaanKnoetze / wc-site-visibility-badge.php
Created September 13, 2024 15:24
Remove the site visibility badges (e.g. "Coming soon", "Store coming soon", and "Live") introduced by WooCommerce in version 9.1
<?php
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
if ( is_object( $wp_admin_bar ) && $wp_admin_bar->get_node( 'woocommerce-site-visibility-badge' ) ) {
$wp_admin_bar->remove_node( 'woocommerce-site-visibility-badge' );
}
}, 100 );
@RiaanKnoetze
RiaanKnoetze / functions.php
Created June 21, 2024 09:19
Remove specific endpoints from WooCommerce my-account page
<?php
add_filter( 'woocommerce_account_menu_items', 'customize_my_account_menu' );
function customize_my_account_menu( $items ) {
// Remove the 'downloads' endpoint
unset($items['downloads']);
// Remove the 'edit-address' endpoint
unset($items['edit-address']);
return $items;
@RiaanKnoetze
RiaanKnoetze / woocommerce-force-display-state.php
Created May 13, 2024 10:13
A WooCommerce code snippet that forces the 'state' field to always display on checkout pages.
<?php
/**
* Modifies the billing address fields to make the state field required.
*
* @param array $address_fields The array of address fields used in WooCommerce checkout.
* @return array The modified array of address fields with 'state' field set as required.
*/
function force_state_field_default_required( $address_fields ) {
// Set the 'required' flag for the 'billing_state' field to true.
$address_fields['billing_state']['required'] = true;
@RiaanKnoetze
RiaanKnoetze / woocommerce-subscription-email-notifications.php
Created April 29, 2024 21:22
Sends custom email notifications for WooCommerce subscription status changes from on-hold to active and pending-cancel to active.
<?php
// Hook for reactivation from 'on-hold' to 'active'
add_action('woocommerce_subscription_status_on-hold_to_active', 'send_custom_email_on_reactivation', 10, 1);
function send_custom_email_on_reactivation($subscription) {
$user_email = $subscription->get_billing_email();
// Optional: Check if this is an admin reactivation
if (is_admin() && current_user_can('manage_woocommerce')) {
$action = 'admin reactivated';
@RiaanKnoetze
RiaanKnoetze / cross-sell-generator.php
Last active February 24, 2024 10:05
Cross Sell Auto Generator
<?php
/**
* Filter the cross-sells displayed in the cart to always show specific products.
*/
function custom_filter_woocommerce_cart_cross_sells( $cross_sell_ids, $cart ) {
// Specify the IDs of the products you want to always show as cross-sells.
$custom_cross_sell_ids = array( '1', '2' );
// Return your custom cross-sell product IDs.
return $custom_cross_sell_ids;
@RiaanKnoetze
RiaanKnoetze / style.css
Created November 2, 2020 10:52
Permanently show price, add-to-cart button and product title when using Storefront Galleria
@media screen and (min-width: 768px) {
.site-main ul.products li.product, .smm-mega-menu ul.products li.product {
overflow: visible;
}
.site-main ul.products li.product .button,
.site-main ul.products li.product .g-product-title,
.smm-mega-menu ul.products li.product .button,
.smm-mega-menu ul.products li.product .g-product-title {
display: block;
@RiaanKnoetze
RiaanKnoetze / product-addons.php
Created October 30, 2020 16:09
Convert Product Addon Field to Select2
<!-- Add following snippet to "Header & Footers WordPress Plugin. Replace wc.local with your own website URL -->
<link rel='stylesheet' id='select2-css' href='https://wc.local/wp-content/plugins/woocommerce/assets/css/select2.css?ver=4.6.1' media='all' />
<script src="https://wc.local/wp-content/plugins/woocommerce/assets/js/selectWoo/selectWoo.full.min.js?ver=1.0.6" id="selectWoo-js"></script>
<script>
jQuery( document ).ready(
function ($) {
$( '.wc-pao-addon-select' ).filter( ':not(.enhanced)' ).each(
function() {
@RiaanKnoetze
RiaanKnoetze / wc_stripe_supported_countries.php
Last active August 14, 2020 15:14
Add China country support in WooCommerce Stripe where offices are located in Hong Kong
<?php
add_filter( 'wc_stripe_supported_countries', 'wc_stripe_CN_support', 10, 1 );
function wc_stripe_CN_support( $supported_countries ) {
$supported_countries = array(
'CN', // China
);
return $supported_countries;
}
@RiaanKnoetze
RiaanKnoetze / style.css
Created April 24, 2018 09:20
Change Main Navigation submenu background colour on hover when using Storefront
.main-navigation ul.menu ul li:hover>a,
.main-navigation ul.nav-menu ul li:hover>a {
background-color: #ff2b71;
}
@RiaanKnoetze
RiaanKnoetze / style.css
Last active December 6, 2017 06:01
Update Galleria child theme styles to ALWAYS show title, pricing and buttons
.site-main ul.products li.product, .smm-mega-menu ul.products li.product {
overflow: visible;
}
.site-main ul.products li.product .button,
.site-main ul.products li.product .g-product-title,
.smm-mega-menu ul.products li.product .button,
.smm-mega-menu ul.products li.product .g-product-title {
display: block;
opacity: 1;