Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
damiencarbery / cart-contents-shortcode.php
Last active January 11, 2024 13:32
Refund Requests for WooCommerce Customers - using Contact Form 7 - As a response to a comment on Beka Rice's "Add Refund Requests for WooCommerce Customers" post on sellwp.com I decided to implement the same concept with Contact Form 7. https://www.damiencarbery.com/2016/11/refund-requests-for-woocommerce-customers-using-contact-form-7/
<?php
// To the CF7 form add:
// [dynamic_hidden 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();
<?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: $
*/
<?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
*/
<?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 December 20, 2016 21:57
Customise WooCommerce template files in a plugin
<?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 October 14, 2022 10:08
Debugging with WordPress - enable WP_DEBUG, with sample usage to investigate wc_get_template()
<?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 June 7, 2020 00:01
Standalone WordPress Scripts
<?php
define('WP_USE_THEMES', false);
require( 'wp-blog-header.php' );
bloginfo( 'name' );
<?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: 8.0.2
*/
@damiencarbery
damiencarbery / aj-demo-ajax-code.js
Last active June 9, 2020 21:06
Demo of AJAX in WordPress
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 February 13, 2017 10:55
Woocommerce - Promote Free Shipping
<?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' ];