Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
damiencarbery / rest-api-change-field-value.php
Created May 22, 2026 15:18
Change a REST API field value - Change the value of a field in a REST API endpoint. https://www.damiencarbery.com/2026/05/change-a-rest-api-field-value/
<?php
/*
Plugin Name: REST API - change field value
Plugin URI: https://www.damiencarbery.com
Description: Change the value of a field in a REST API endpoint.
Author: Damien Carbery
Version: 0.1.20260522
*/
@damiencarbery
damiencarbery / example-check-if-product-limited.php
Created May 18, 2026 15:30
Limit item order quantity for WooCommerce - Limit the quantity of an item that can be ordered. https://www.damiencarbery.com/2026/05/limit-item-order-quantity-for-woocommerce/
<?php
add_filter( 'limit_order_quantity_product_limited', 'check_if_product_limited', 10, 2 );
// Check to see if this limit applies to this product.
// Return true if the product is quantity limited (to prevent adding more to the cart).
// Return false if there is no special quantity limit.
function check_if_product_limited( $limited, $product ) {
// Hoodies category has ID 18.
if ( in_array( 18, $product->get_category_ids() ) ) {
return true;
@damiencarbery
damiencarbery / the-events-calendar-json-ld-fields.php
Created May 18, 2026 12:51
Add fields to event JSON+LD to fix warnings from Google Search Console.
<?php
// Add fields to event JSON+LD to fix warnings from Google Search Console.
add_filter( 'tribe_json_ld_event_object', 'ccs_add_data_to_json_ld', 10, 2 );
function ccs_add_data_to_json_ld( $data, $args ) {
$fields = array( 'location', 'organizer', 'image', 'offers', 'description' );
foreach ( $fields as $field ) {
if ( empty( $data->$field ) ) {
$data->$field = '';
}
@damiencarbery
damiencarbery / sticky-nav-gp.php
Created March 12, 2026 14:38
Sticky Navigation - stick header area too - To set the navigation and header as sticky in GeneratePress the height of the header is needed for the navigation 'top' property. Also scroll to # anchors (less height of sticky header and sticky nav).
<?php
/*
Plugin Name: Sticky Navigation - stick header area too
Plugin URI: https://www.damiencarbery.com/
Description: To set the navigation and header as sticky in GeneratePress the height of the header is needed for the navigation 'top' property. Also scroll to # anchors (less height of sticky header and sticky nav).
Author: Damien Carbery
Version: 0.3.20260312
*/
<?php
/*
* Plugin Name: New badge for Product Collection block
* Description: Insert a 'New' badge after the product price.
* Plugin URI: https://www.kathyisawesome.com/leverage-block-hooks-to-insert-content/
* Author: Kathy Awesome
* Author URI: https://www.kathyisawesome.com
* Requires Plugins: woocommerce
* Version: 0.1
*/
@damiencarbery
damiencarbery / allow-one-download-always.php
Last active February 5, 2026 14:49
Example extensions for my 'Downloads for logged in users' plugin (https://wordpress.org/plugins/downloads-for-logged-in-users/)
<?php
/*
Plugin Name: Allow specific download always
Plugin URI: https://www.damiencarbery.com/downloads-for-logged-in-users/
Description: With the <a href="https://wordpress.org/plugins/downloads-for-logged-in-users/">Downloads for logged in users</a> plugin, always allow one download.
Author: Damien Carbery
Version: 0.1
Requires Plugins: downloads-for-logged-in-users
*/
@damiencarbery
damiencarbery / public-holidays.html
Created October 8, 2025 17:03
Irish Public Holidays - some AJAX - Playing around with Javascript and AJAX to display a list of Irish public holidays. https://www.damiencarbery.com/2025/10/irish-public-holidays-some-ajax/
<!DOCTYPE html>
<html lang='en-GB'>
<head>
<meta charset='UTF-8'>
<meta name='robots' content='noindex',' nofollow' />
<meta name='viewport' content='width=device-width',' initial-scale=1'>
<title>Public Holidays</title>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css' rel='stylesheet' crossorigin='anonymous'>
<style>
.container { padding-top: 50px; }
@damiencarbery
damiencarbery / em-custom-placeholder.php
Created September 8, 2025 10:29
Events Manager - custom placeholder demos - Demonstration of static and dynamic custom placeholder tags for Events Manager. https://www.damiencarbery.com/2025/09/events-manager-custom-placeholders/
<?php
/*
* Plugin Name: Events Manager - custom placeholder demos
* Description: Demonstration of static and dynamic custom placeholder tags for Events Manager.
* Plugin URI: https://www.damiencarbery.com/2025/09/events-manager-custom-placeholders/
* Author: Damien Carbery
* Author URI: https://www.damiencarbery.com
* Requires Plugins: events-manager
* Version: 0.1.20250908
*/
@damiencarbery
damiencarbery / style-block-editor-links.css
Created September 5, 2025 08:54
Highlight Block Editor Links - Style the links in block editor to make them easy to find - while fixing broken links. https://www.damiencarbery.com/2025/09/highlight-block-editor-links/
@damiencarbery
damiencarbery / checkout-block-additional-checkbox-field.php
Last active June 3, 2025 15:08
Add fields to WooCommerce Checkout block - Experiments using WooCommerce API to add fields to the Checkout block. https://www.damiencarbery.com/2025/06/add-fields-to-woocommerce-checkout-block/
<?php
// This code is for a checkbox in the Order Information area.
add_action( 'woocommerce_init', 'cbt_add_newsletter_checkbox' );
function cbt_add_newsletter_checkbox() {
woocommerce_register_additional_checkout_field(
array(
'id' => 'namespace/marketing-opt-in',
'label' => 'Do you want to subscribe to our newsletter?',
'location' => 'order',