Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
damiencarbery / attach-order-files-to-wc-order-email.php
Last active Dec 1, 2021
Attach files to WooCommerce order email - Upload files to an order to attach them to the WooCommerce Order Completed email.
View attach-order-files-to-wc-order-email.php
<?php
/*
Plugin Name: Attach files to WooCommerce order email
Plugin URI: https://www.damiencarbery.com/2021/05/attach-files-to-woocommerce-order-email/
Description: Upload files to an order to attach them to the WooCommerce Order Completed email.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
@damiencarbery
damiencarbery / genesis-hide-old-post-dates.php
Last active Feb 14, 2021
Genesis Hide Old Post Dates - Do not show post date on posts older than 30 days.
View genesis-hide-old-post-dates.php
<?php
/*
Plugin Name: Genesis Hide Old Post Dates
Plugin URI: https://www.damiencarbery.com/2021/02/hide-old-post-dates-in-genesis/
Description: Do not show post date on posts older than 30 days.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.2
*/
View delete-orders.php
<?php
/*
// Restrict who can access this script.
$permitted_ips = array('12.34.56.78', '87.65.43.21');
if (in_array($_SERVER['REMOTE_ADDR'], $permitted_ips) == false) {
header('HTTP/1.0 403 Forbidden');
die();
}
*/
View acf-percentage-circle.php
<?php
/*
Plugin Name: ACF - Percentage Circle
Plugin URI: https://www.damiencarbery.com/2020/11/percentage-circle-block/
Description: Block to display a percentage circle with animation. Based on: https://codepen.io/sergiopedercini/pen/jmKdbj
Author: Damien Carbery
Version: 0.1
*/
View magazine-pro-no-menu-single-posts.php
<?php
/*
Plugin Name: Magazine Pro - Hide menu on single posts
Plugin URI: https://www.damiencarbery.com
Description: Hide the After Header Menu when on single posts. Asked on Genesis Facebook group.
Author: Damien Carbery
Version: 0.1
*/
add_action( 'genesis_after_header', 'mp_omit_after_header_menu_on_single_posts', 5 );
@damiencarbery
damiencarbery / email-order-details.php
Created Oct 18, 2020
Add column to WooCommerce order email - Add an extra column to the WooCommerce order email. https://www.damiencarbery.com/2020/10/add-column-to-woocommerce-order-email/
View email-order-details.php
<?php
/**
* Order details table shown in emails.
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@damiencarbery
damiencarbery / json-encoded-markup.js
Created Oct 4, 2020
Randomise order of items - Randomise the order that a group of items are displayed, even when the page is cached. https://www.damiencarbery.com/2020/10/randomise-order-of-items/
View json-encoded-markup.js
document.addEventListener("DOMContentLoaded", function(event) {
let logos = ["<div class=\"item\"><img src=\"https:\/\/dummyimage.com\/400x400\/306933\/afb3f0.png&text=1\" \/><\/div>", "etc", "etc"];
fisherYates(logos); // Shuffle the array.
var logos_html = "";
logos.forEach(function(item, index, array) {
logos_html += item;
})
var container = document.getElementById( "logos" );
container.innerHTML = logos_html;
});
@damiencarbery
damiencarbery / accordion-block-export.xml
Created Sep 28, 2020
Distribute Genesis Custom Block in a plugin - Include the Genesis Custom Block definition as part of the plugin to simplify distribution. https://www.damiencarbery.com/2020/09/distribute-genesis-custom-block-in-a-plugin/
View accordion-block-export.xml
<item>
<title>Accordion block</title>
<link>https://example.com/genesis_custom_block/accordion-block/</link>
<pubDate>Tue, 15 Sep 2020 12:16:12 +0000</pubDate>
<dc:creator><![CDATA[me]></dc:creator>
<guid isPermaLink="false">https://example.com/?post_type=genesis_custom_block&#038;p=8</guid>
<description></description>
<content:encoded><![CDATA[{"genesis-custom-blocks\/accordion-block":{"name":"accordion-block","title":"Accordion block","excluded":[],"icon":"list","category":{"slug":"widgets","title":"Widgets","icon":null},"keywords":[""],"fields":{"title":{"name":"title","label":"Title","control":"text","type":"string","order":0,"location":"editor","width":"100","help":"","default":"","placeholder":"","maxlength":null},"content":{"name":"content","label":"Content","control":"textarea","type":"textarea","order":1,"location":"editor","width":"100","help":"","default":"","placeholder":"","maxlength":null,"number_rows":4,"new_lines":"autop"}}}}]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:
@damiencarbery
damiencarbery / css-slider.php
Last active Sep 21, 2020
Pure CSS slider - proof of concept - A slider using only CSS transitions. https://www.damiencarbery.com/2020/09/pure-css-slider-proof-of-concept/
View css-slider.php
<!DOCTYPE html>
<html>
<head>
<title>CSS fade in/out slider</title>
</head>
<?php
$slides = array( '<div><img src="http://placekitten.com/g/612/612"/></div>',
'<div><img src="https://unsplash.it/id/237/612/612"/></div>',
'<div><img src="https://unsplash.it/id/400/612/612"/></div>',
'<div><img src="https://unsplash.it/id/181/612/612"/></div>',
@damiencarbery
damiencarbery / block-accordion-block.php
Last active Mar 15, 2021
Demo of Genesis Custom Blocks - A simple custom block delivered in a plugin. https://www.damiencarbery.com/2020/09/demo-of-genesis-custom-blocks/
View block-accordion-block.php
<details class="genesis-custom-block <?php block_field('className'); ?>">
<summary class="item-title"><?php block_field( 'title' ); ?></summary>
<div class="item-content"><?php block_field( 'content' ); ?></div>
</details>