Skip to content

Instantly share code, notes, and snippets.

View autocomplete-orders.php
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
@digamber89
digamber89 / filtes.php
Last active Nov 29, 2015
Show Filters Attached to Hook
View filtes.php
<?php
/* Attaching to Init because plugin files and theme files all have been loaded by this point and no output has been generated */
/* using anonymous function */
add_action('init', function(){
/* replace wp_head with any filter or action hook */
$hooks = digthis_see_hooked_actions('wp_head');
var_dump($hooks);
});
function digthis_see_hooked_actions($hook = NULL){
@digamber89
digamber89 / removeSingleton.php
Created Nov 29, 2015
Singleton Class Unhook action and Filters
View removeSingleton.php
class myClass{
protected static $instance = null;
public function __construct(){
add_filter('the_content', array($this, 'add_text'));
}
public static function get_instance(){
// If the single instance hasn't been set, set it now.
@digamber89
digamber89 / load-admin-scripts.php
Created Jul 14, 2016
Correct way to enqueue styles and scripts for your plugin option pages
View load-admin-scripts.php
// Load the scripts conditionally
add_action( 'load-' . $menu_page, array($this, 'enqueue_scripts') );
/* This function is only called when our plugin's page loads! */
public function enqueue_scripts(){
add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts') );
}
/* Load Scripts only if necessary */
public function load_admin_scripts(){
View Gzip Compression
# Gzip compression
<IfModule mod_deflate.c>
# Active compression
SetOutputFilter DEFLATE
# Force deflate for mangled headers
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Don’t compress images and other uncompressible content
View Retina Ready WordPress Logo
View change-front-page-template.php
add_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if ( is_front_page() ) {
$new_template = locate_template( array( 'tpl-duplicate-homepage.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
View form-checkout.php
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.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
View filter-cpt-by-taxonomy.php
<?php
/**
* Display a custom taxonomy dropdown in admin
* @author Mike Hemberger
* @link http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
*/
add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
global $typenow;
$post_type = 'team'; // change to your post type
@digamber89
digamber89 / add-nav-menu-image-field.php
Created Jul 3, 2017
Add Image Upload To Navigation Menu
View add-nav-menu-image-field.php
<?php
/**
* Menu item custom fields example
*
* Copy this file into your wp-content/mu-plugins directory.
*
* @package Menu_Item_Custom_Fields_Example
* @version 0.2.0
* @author Dzikri Aziz <kvcrvt@gmail.com>
*