Skip to content

Instantly share code, notes, and snippets.

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;
}
const dark = window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)') &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
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');
}
<body class="dark">
my app
</body>
@media (prefers-color-scheme: dark) {
background: black;
}
@bryceadams
bryceadams / gist:925a183619376feb5dcf5de9a84bcdd8
Created July 21, 2018 02:49
Metorik - Move add cart popup placement.
add_filter('metorik_acp_placement', function() {
return 'left';
});
@bryceadams
bryceadams / gist:4bcfce7f1ff341f9b1ad8cc98b3417bb
Last active July 20, 2018 08:25
Metorik - Stop cart checkout button 'popup' appearing.
add_filter('metorik_acp_checkout_button', '__return_false');
@bryceadams
bryceadams / add-cart-email-form.php
Created July 5, 2018 07:43
Metorik Helper 1.0.0 - Add Cart Email Form template file
<?php
/**
* Metorik: Add cart email form template.
*
* This template can be overriden by copying this file to your-theme/metorik/add-cart-email-form.php
*
* Variables available:
* 1. $title - Title (set in Metorik).
* 2. $email_usage_notice - Email usage notice (if enabled in Metorik and customer didn't opt-out).
*
@bryceadams
bryceadams / wc-custom-meta-get.php
Created April 10, 2018 05:42
WC Custom Meta Getting
<?php
$order_id = 125;
echo get_post_meta( $order_id, 'payment_gateway_fee', true ); // 1.60