Skip to content

Instantly share code, notes, and snippets.

@NickGreen
NickGreen / postcss-examples.css
Created June 6, 2025 22:06
PostCSS Example sheet
/* Custom Properties */
:root {
--wp--custom--spacing--block-gap: 2rem;
--wp--custom--color--primary: #0073aa;
--wp--custom--color--secondary: #23282d;
--wp--custom--transition--duration: 0.3s;
--wp--custom--border-radius: 4px;
}
/* Advanced Block Styling */
@NickGreen
NickGreen / template.html
Created June 6, 2025 21:59
Example FSE template html file
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
<main class="wp-block-group">
<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"var:preset|spacing|60","bottom":"var:preset|spacing|60"}}},"backgroundColor":"base","textColor":"contrast","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull has-contrast-color has-base-background-color has-text-color has-background" style="padding-top:var(--wp--preset--spacing--60);padding-bottom:var(--wp--preset--spacing--60)">
<!-- wp:heading {"textAlign":"center","level":1,"style":{"typography":{"fontStyle":"normal","fontWeight":"700"}}} -->
<h1 class="wp-block-heading has-text-align-center" style="font-style:normal;font-weight:700"><?php echo esc_html__( 'Welcome to Our Platform', 'your-theme-textdomain' ); ?></h1>
<!-- /wp:heading -->
@NickGreen
NickGreen / cart_total_notice.php
Last active November 2, 2021 16:33
Add cart and checkout notices if total less than $25
<?php
add_action( 'woocommerce_before_cart_table', 'free_shipping_notice' );
add_action( 'woocommerce_checkout_before_customer_details', 'free_shipping_notice' );
function free_shipping_notice() {
if ( 25 > WC()->cart->get_total() ) {
echo '<div style="color: #e08e79;">All orders over $25 ship free</div>';
}
}
@NickGreen
NickGreen / prod_cat_email.php
Last active November 2, 2021 16:32
Add Product Category to email subject WooCommerce
<?php
add_filter( 'woocommerce_email_subject_new_order', 'customizing_new_order_subject', 10, 2 );
function customizing_new_order_subject( $formated_subject, $order ) {
$email = WC()->mailer->get_emails()['WC_Email_New_Order'];
$subject = $email->get_option( 'subject', $email->get_default_subject() );
$product_categories = array();
foreach ( $order->get_items() as $item ) {
$product_categories[] = implode( ', ', wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) ) );
@NickGreen
NickGreen / md5_hash.js
Created April 27, 2021 16:24
MD5 hashing in JS example
additionalFields.forEach( ( { label, type, required, options = '' } ) => {
if ( '' !== type ) {
var MD5 = function(d){var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r<d.length;r++)_=d.charCodeAt(r),f+=m.charAt(_>>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<<m%32;return _}function V(d){for(var _="",m=0;m<32*d.length;m+=8)_+=String.fromCharCode(d[m>>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n<d.length;n+=16){var h=m,t=f,g=r,e=i;f=md5_ii(f=md5_ii(f=md5_ii(f=md5_ii(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_ff(f=md5_ff(f=md5_ff(f=md5_ff(f,r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+0],7,-680876936),f,r,d[n+1],12,-389564586),m,f,d[n+2],17,606105819),i,m,d[n+3],22,-1044525330),r=md5_ff(r,i=md5_ff
@NickGreen
NickGreen / return_to_shop.php
Created February 15, 2021 16:24
Return to shop link WooCommerce
<?php
add_filter( 'woocommerce_return_to_shop_redirect', function() { return '/shop'; });
@NickGreen
NickGreen / currency_position.php
Last active February 8, 2021 19:48
Switch currency position to left for USD
<?php
add_filter('woocommerce_price_format', 'woo_custom_format_position', 999, 2);
function woo_custom_format_position( $format, $currency_pos )
{
/*'left':$format = '%1$s%2$s';
'right':$format = '%2$s%1$s';
'left_space':$format = '%1$s&nbsp;%2$s';
'right_space':$format = '%2$s&nbsp;%1$s';
*/
@NickGreen
NickGreen / get_location.php
Created February 3, 2021 20:54
Get customer location
<?php
if( get_current_user_id() > 0 ) { // if customer exists already
$country = WC()->customer->get_billing_country();
} else { // if not-logged-in, need to use geolocation data
// Get an instance of the WC_Geolocation object class
$geo_instance = new WC_Geolocation();
// Get geolocated user geo data.
$user_geodata = $geo_instance->geolocate_ip();
// Get current user GeoIP Country
@NickGreen
NickGreen / custom_price.php
Last active November 22, 2021 02:19
Custom price based on custom field
<?php
// Save custom calculated price as custom cart item data
add_filter( 'woocommerce_add_cart_item_data', 'save_custom_fields_data_to_cart', 10, 2 );
function save_custom_fields_data_to_cart( $cart_item_data, $product_id ) {
if ( CUSTOMER_IS_IN_US ) {
// Set the custom data in the cart item
$cart_item_data['custom_price'] = GET_PRICE_FROM_CUSTOM_FIELD;
@NickGreen
NickGreen / business_hours.php
Created December 2, 2020 18:03
Disable all autoupdates during business hours
<?php
// Place this snippet in config.php file
// Suspend all updates when outside of business hours, 9:00 AM to 5:30 PM
$updates_suspended = (date('Hi') < 0900 || date('Hi') > 1730);
define( 'AUTOMATIC_UPDATER_DISABLED', $updates_suspended );