Skip to content

Instantly share code, notes, and snippets.

Avatar

Damien Carbery damiencarbery

View GitHub Profile
View cart-contents-shortcode.php
<?php
// To the CF7 form add:
// [dynamichidden dynamichidden-cart "cart_contents"]
// In the CF7 Mail add:
// [dynamichidden-cart]
// The "cart_contents" uses this code
add_shortcode( 'cart_contents', 'dcwd_cart_contents' );
function dcwd_cart_contents($atts, $content, $code) {
$cart_contents = array();
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
*/
View eircode-ireland-addresses.php
<?php
/*
Plugin Name: Eircode field for Irish addresses
Plugin URI: http://www.damiencarbery.com
Description: Eircode field for Ireland addresses in WooCommerce.
Author: Damien Carbery
Version: $Revision: $
*/
@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 Jun 7, 2020
Standalone WordPress Scripts
View basic-get-site-title.php
<?php
define('WP_USE_THEMES', false);
require( 'wp-blog-header.php' );
bloginfo( 'name' );
View add-cf7-after-short-description-by-action.php
<?php
/*
Plugin Name: CF7 form to all products (after short description, with add_action)
Plugin URI: http://www.damiencarbery.com
Description: Append a Contact Form 7 form to the Short Description section of all Woocommerce products.
Author: Damien Carbery
Version: 0.1
WC tested up to: 4.2.0
*/
@damiencarbery
damiencarbery / aj-demo-ajax-code.js
Last active Jun 9, 2020
Demo of AJAX in WordPress
View aj-demo-ajax-code.js
jQuery(document).ready( function(){
jQuery('.count_btn').on('click', function(e) {
var post_type = jQuery(this).data( 'type' ); // Get post type via the 'data-type' attribute of the button.
jQuery('#'+post_type+'_count').html('?'); // Clear existing value.
e.preventDefault();
jQuery.ajax({
url : aj_ajax_demo.ajax_url, // Note that 'aj_ajax_demo' is from the wp_localize_script() call.
@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' ];
You can’t perform that action at this time.