Skip to content

Instantly share code, notes, and snippets.

@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;
@RiaanKnoetze
RiaanKnoetze / functions.php
Created November 8, 2017 06:25
Change the number of categories and the order on the homepage when using Storefront
add_filter('storefront_product_categories_shortcode_args','custom_storefront_category_per_page' );
// Category Products
function custom_storefront_category_per_page( $args ) {
$args['number'] = 10;
$args['orderby'] = 'name';
return $args;
}
@RiaanKnoetze
RiaanKnoetze / functions.php
Created November 7, 2017 03:41
Change the orderby parameter for the Featured Products section in Storefront for WooCommerce
add_filter('storefront_featured_products_args','custom_storefront_featured_product_order' );
// Featured Products Order
function custom_storefront_featured_product_order( $args ) {
$args['orderby'] = 'title;
return $args;
}
@RiaanKnoetze
RiaanKnoetze / style.css
Created August 2, 2017 08:57
Remove the padding and margin of the page content on the homepage when using Storefront.
.page-template-template-homepage.has-post-thumbnail .type-page.has-post-thumbnail {
padding-top: 0;
padding-bottom: 0;
margin: 0;
}