Skip to content

Instantly share code, notes, and snippets.

View jan-koch's full-sized avatar

Jan Koch jan-koch

View GitHub Profile
@jan-koch
jan-koch / woo-add-custom-sku.php
Last active July 16, 2021 10:39
Add a custom SKU field to WooCommerce products.
<?php
function jk_add_custom_sku() {
$args = array(
'label' => __( 'Custom SKU', 'woocommerce' ),
'placeholder' => __( 'Enter custom SKU here', 'woocommerce' ),
'id' => 'jk_sku',
'desc_tip' => true,
'description' => __( 'This SKU is for internal use only.', 'woocommerce' ),
);
@jan-koch
jan-koch / email-order-items.php
Last active April 17, 2021 15:41
Email order items template from WooCommerce, containing a custom snippet to show a custom SKU for each product - only in admin emails. This file goes into wp-content/themes/your-child-theme/woocommerce/emails.
<?php
/**
* Email Order Items
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-items.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
@jan-koch
jan-koch / block.js
Created December 11, 2018 16:22
Functionality for the Gutenberg block to embed Github gists
/**
* BLOCK: wpmastery-code-block
*
* Registering a basic block with Gutenberg.
* Simple block, renders and saves the same content without any interactivity.
*/
// Import CSS.
import './style.scss';
import './editor.scss';
@jan-koch
jan-koch / sticky-menu.js
Created March 5, 2019 05:46
Small JavaScript snippet to make the Genesis site header stick to the top when scrolling down.
jQuery(function ($) {
$(window).scroll(function () {
var yPos = ($(window).scrollTop());
if (yPos > 200) { // show sticky menu after screen has scrolled down 200px from the top.
// add a custom class to the site header for custom styling.
$(".site-header").addClass("is-sticky");
// if you feel brave, switch logos (e.g. to match different background colors).
$("img.custom-logo").attr("src", "http://localhost/wp-content/path/to/sticky-logo.svg");
} else {
@jan-koch
jan-koch / functions.php
Created April 9, 2019 14:11
Remove comments from the single post layout in the WP Astra theme. This snippet goes into your functions.php.
// Remove the default comments from Astra.
add_action(
'init',
function() {
if ( class_exists( 'Astra_Loop' ) ) {
remove_action( 'astra_template_parts_content', array( Astra_Loop::get_instance(), 'template_parts_comments' ), 15 );
}
},
11
);
@jan-koch
jan-koch / git-create-repo.sh
Created May 22, 2019 06:16
A simple bash script to create a repository from the console.
#! /usr/bin/bash
NAME=$1
TYPE=$2
echo "Creating the repository"
gh re --browser false --new "$NAME" --type "$TYPE"
mkdir "$NAME"
cd "$NAME"
@jan-koch
jan-koch / git-create-repo.sh
Last active May 24, 2019 13:06
A simple bash script to create a repository from the console. Be sure to replace "USERNAME" with your Github user name. This script utilizes nodegh.io.
#! /usr/bin/bash
NAME=$1
TYPE=$2
echo "Creating the repository"
gh re --browser false --new "$NAME" --type "$TYPE"
mkdir "$NAME"
cd "$NAME"
@jan-koch
jan-koch / export_database_with_replace.sh
Created June 8, 2019 07:20
Bash script to export a database from a WordPress container and perform a search/replace using the UNIX command "sed". Script is based on https://hub.docker.com/r/jankoch/wordpress.
#! /bin/bash
CONTAINER=$1
SEARCH=$2
REPLACE=$3
# Dump the file
DUMP=$(docker exec $CONTAINER wp db export --add-drop-table --porcelain)
@jan-koch
jan-koch / docker-compose.yml
Created June 8, 2019 13:43
Example of a docker-compose file to create a local WordPress development setup with Docker.
version: '3.2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: on-failure
environment:
# Grab this data from wp-config.php
# TODO: Update DB_HOST in wp-config.php to "db:port"
@jan-koch
jan-koch / Jenkinsfile
Last active September 12, 2019 05:08
Jenkinsfile for automated deployment with Github and PHPloy
pipeline {
agent any
// Pull the repo first.
stages {
stage( 'Checkout Repo' ) {
steps {
checkout scm
}
}
stage( 'Deploy' ) {