Skip to content

Instantly share code, notes, and snippets.

Avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / mixin-tags.scss
Last active May 16, 2017
Mixin to display a list of links like label tags - used on www.ownsit.com.au
View mixin-tags.scss
@mixin tags {
ul {
margin: 0;
li {
list-style: none;
display: inline-block;
&:before {
@doubleedesign
doubleedesign / wc-product-checklist.php
Created May 16, 2017
WooCommerce - template to output all product names and their variation images. This template provides a quick way to output the titles of all products, with their variation images underneath. Useful as a quick way to check which product variations do not have an image, or to check that they are all correct.
View wc-product-checklist.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing document</title>
<style type="text/css">
* {
font-family: Lucida Grande, Lucida Sans Unicode, Lucida Sans, DejaVu Sans, Verdana, sans-serif;
}
.wrapper {
@doubleedesign
doubleedesign / menu-walkers.php
Created May 23, 2017
My first go at a custom menu walker in WordPress. Starting with the example from WordPress.org, I added code to output an SVG icon as part of the link on each menu item.
View menu-walkers.php
if ( ! class_exists( 'doublee_Secondary_Walker' ) ) :
class doublee_Secondary_Walker extends Walker_Nav_Menu {
/**
* Start the element output.
*
* Adds main/sub-classes to the list items and links.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
@doubleedesign
doubleedesign / wc-house-product-attributes.php
Last active May 26, 2017
Custom display of product attributes for a home builder or property developer site. Used on www.davrose.com.au
View wc-house-product-attributes.php
<?php
/*
Highly customised output of product attributes
These functions can be used in hooks in functions/woocommerce.php or directly in templates
Functions:
1. doublee_home_room_attributes() gets the number of bedrooms, bathrooms and car spaces and outputs them as a list.
2. doublee_duo_home_room_attributes() gets the number of bedrooms, bathrooms and car spaces for both residences and outputs them in a condensed list. Used where doublee_home_room_attributes() is not appropriate
2. doublee_home_dimensions_attributes() gets the living area size, total area size, minimum block width and number of storeys and displays them in a table.
3. doublee_home_floorplan_image() gets and outputs the floorplan image, which is an ACF field.
@doubleedesign
doubleedesign / wc-add-product-descriptions-to-order-emails.php
Created Jul 4, 2017
Function to add a list of item descriptions to WooCommerce order confirmation emails
View wc-add-product-descriptions-to-order-emails.php
<?php
// Add item descriptions to order confirmation emails
function doublee_add_purchase_details($order_id) {
echo '<h2>Item details</h2>';
echo '<ul>';
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item) {
$product_id = $item['product_id'];
$product = get_post($product_id);
echo '<li>';
@doubleedesign
doubleedesign / wc-add-notification-recipient-on-user-registration.php
Last active Jul 11, 2017
Create WooCommerce Advanced Notifications recipient upon user registration, and add authors as notification recipients on the products they create automatically. First function sets the username as the notification recipient name, user's email as the notification email address (doesn't set any of the other fields, though these could be added), a…
View wc-add-notification-recipient-on-user-registration.php
<?php
// Create a WooCommerce Advanced Notifications recipient when a user registers
add_action( 'user_register', 'doublee_also_add_a_wc_notification_recipient', 10, 1 );
function doublee_also_add_a_wc_notification_recipient( $user_id ) {
global $wpdb;
if ( isset( $_POST['username'] ) ) { // triggered by my front-end form (Ninja Form). Your field name may be different
$doublee_recipient_name = sanitize_text_field( stripslashes( $_POST['username'] ) );
@doubleedesign
doubleedesign / select-referrer-option.js
Created Oct 3, 2017
Add classes to selectbox options that should theoretically match possible referring URL slugs; get the referring URL and select the option that matches. Being used to choose a WooCommerce variation relevant to the grouped product that the user came from.
View select-referrer-option.js
jQuery(document).ready(function() {
var referrer = document.referrer;
var urlArray = referrer.split('/');
var referrerSlug = urlArray.slice(-1)[0];
jQuery("select#location > option").each(function() {
var label = this.value;
label = label.replace(/\s+/g, '-').toLowerCase(); //lower case and replace spaces with hyphens
label = label.replace("'", ""); //strip apostrophes
@doubleedesign
doubleedesign / type-scales.scss
Last active Jan 15, 2018
SCSS mixins to easily utilise the proportional type settings chosen using type-scale.com. Note: I have since created a more streamlined version of this: https://gist.github.com/doubleedesign/5a9321bceb4c7f5668c12bc668b9b796
View type-scales.scss
/*==============================================
TYPE SCALES - www.type-scale.com
Note: the base font size and line height is set under "set the body font" in _typography.scss,
Paragraph margins don't change according to type scale used so they are set once in _typography.scss
The base font size can be changed at different breakpoints and the type will scale accordingly since it's set in ems.
==============================================*/
@mixin use-type-scales {
p,
main ul,
@doubleedesign
doubleedesign / _typescales.scss
Last active Jan 15, 2018
Improved SCSS mixin to easily utilise the proportional type settings chosen using type-scale.com. A streamlining of my previous mixins - https://gist.github.com/doubleedesign/45850d90c80deef79880361f984a3136
View _typescales.scss
/*==============================================
TYPE SCALES - inspired by www.type-scale.com
Notes:
- The base font size and line height are set as variables, called in _typography.scss
- H1s are two steps up from H2s to make them stand out more
- Paragraph margins don't change according to type scale used so they are set once in _typography.scss
- The base font size can be changed at different breakpoints and the type will scale accordingly since it's set in ems.
- Breakpoint mixins and/or media queries can be used to change the typescale at different viewports
==============================================*/
@doubleedesign
doubleedesign / cpt-address.php
Last active Feb 24, 2018
WordPress custom post type for addresses, ACF export file of fields, and example markup
View cpt-address.php
<?php
// Register Custom Post Type
function doublee_address_cpt() {
$labels = array(
'name' => 'Addresses',
'singular_name' => 'Address',
'menu_name' => 'Addresses',
'name_admin_bar' => 'Address',
'archives' => 'Address Archives',