Skip to content

Instantly share code, notes, and snippets.

@bryceadams
bryceadams / gist:db6c8669e9e99cb2808c
Last active October 9, 2023 13:55
Clear WooCommerce Cart (when not cart/checkout)
/**
* Clears WC Cart on Page Load
* (Only when not on cart/checkout page)
*/
add_action( 'wp_head', 'bryce_clear_cart' );
function bryce_clear_cart() {
if ( wc_get_page_id( 'cart' ) == get_the_ID() || wc_get_page_id( 'checkout' ) == get_the_ID() ) {
return;
}
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)') {
var windowPrefersDark = window.matchMedia('(prefers-color-scheme: dark)');
var systemColorMode = windowPrefersDark.matches ? 'dark' : 'light';
// need to check in case doesn't exist like with Safari 13.x
if (
'addEventListener' in windowPrefersDark &&
typeof windowPrefersDark.addEventListener === 'function'
) {
windowPrefersDark.addEventListener('change', (event) => {
:root.dark {
color-scheme: light dark;
}
if (color_mode == 'dark') {
document.body.classList.add('dark');
document.documentElement.classList.add('dark');
} else {
document.body.classList.remove('dark');
document.documentElement.classList.remove('dark');
}
const dark = window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)') &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
<body class="dark">
my app
</body>
@media (prefers-color-scheme: dark) {
background: black;
}
add_filter( 'submit_job_form_login_url', 'wpjms_redirect_login_url' );
function wpjms_redirect_login_url() {
return 'http://mysite.com/my-account/';
}
@bryceadams
bryceadams / gist:050d886159265d6f5e6dbce649552704
Last active April 14, 2022 20:59
Disable WooCommerce total spent / order count meta calculations
<?php
add_filter( 'get_user_metadata', 'mtkdocs_filter_user_metadata', 10, 4 );
function mtkdocs_filter_user_metadata( $value, $object_id, $meta_key, $single ) {
// Check if it's one of the keys we want to filter
if ( in_array( $meta_key, array( '_money_spent', '_order_count' ) ) ) {
// Return 0 so WC doesn't try calculate it
return 0;
}
// Default
@bryceadams
bryceadams / metorik_stop_multiple_coupons.php
Last active March 17, 2022 13:23
Plugin to only allow individual use coupons in WooCommerce, even if they have not been set as such.
<?php
/*
Plugin Name: Stop Multiple WooCommerce Coupons
Plugin URI: https://metorik.com
Description: Only allow individual use coupons in WooCommerce, even if they have not been set as such.
Version: 1.0.0
Author: Bryce Adams (Metorik)
Author URI: https://metorik.com
Text Domain: stop-multiple-woocommerce-coupons-metorik
*/