Skip to content

Instantly share code, notes, and snippets.

View BrianHenryIE's full-sized avatar
🇮🇪

Brian Henry BrianHenryIE

🇮🇪
View GitHub Profile
@BrianHenryIE
BrianHenryIE / show-bundled-items-individually-in-pip-packing-lists.php
Created July 28, 2021 21:14
Fix WooCommerce Product Bundles to appear as individual items in Print Invoices & Packing Lists' packing lists.
<?php
/**
* @see https://woocommerce.com/products/print-invoices-packing-lists/
* @see https://woocommerce.com/products/product-bundles/
*/
$show_bundled_items_individually_in_packing_lists = function( string $type, \WC_PIP_Document $document, \WC_Order $order ) {
if ( 'packing-list' !== $type ) {
return;
}
@BrianHenryIE
BrianHenryIE / add-gateway-settings.php
Created May 26, 2021 18:27
to add a button inside payment settings?
<?php
/**
* Register the new field in the array of settings fields for the gateway
*
* @hooked woocommerce_settings_api_form_fields_{$gateway_id}
*
* @param array $settings The gateway's existing settings.
*
* @return array
@BrianHenryIE
BrianHenryIE / which-hook.php
Created May 14, 2021 23:30
Find on which WordPress hook something has happened
<?php
/**
* In this example, we will test has WooCommerce populated the global $product variable.
*
* Basically, we add an action to the WordPress `all` hook, then `error_log` when the criteria is true, and unhook.
*/
global $has_product_global_been_set;
$has_product_global_been_set = function() {
diff --git a/includes/class-wcslack-settings-legacy.php b/includes/class-wcslack-settings-legacy.php
index 6f7be3a..c4102aa 100644
--- a/includes/class-wcslack-settings-legacy.php
+++ b/includes/class-wcslack-settings-legacy.php
@@ -618,7 +618,6 @@ if ( ! class_exists( 'WC_Slack_Settings' ) ) {
if ( isset( $_GET['wcslack_reload_channels'] ) && ( $_GET['wcslack_reload_channels'] == 1 ) ) {
delete_transient( 'wcslack_all_channels' );
- delete_transient( 'wcslack_all_groups' );
@BrianHenryIE
BrianHenryIE / order-status-change.php
Created April 2, 2021 00:28
Determine what changed the order status in WooCommerce
<?php
/**
* When the status is set to pending from completed, record
* what caused/initiated the change.
*
* @hooked woocommerce_order_status_changed
*
* @see https://www.reddit.com/r/woocommerce/comments/mi1f85/status_on_old_orders_change_from_completed_to/
* @see WC_Order::status_transition()
diff --git a/woocommerce-gateway-stats.php b/woocommerce-gateway-stats.php
index e43cef5..e0726f6 100644
--- a/woocommerce-gateway-stats.php
+++ b/woocommerce-gateway-stats.php
@@ -5,7 +5,7 @@ Plugin URI: https://ajdg.solutions/product/woocommerce-gateway-stats/?pk_campaig
Author: Arnan de Gans
Author URI: https://www.arnan.me/?pk_campaign=woo_gateway_stats
Description: See which payment gateways are used the most. This plugin has no settings.
-Version: 1.0.7
+Version: 1.1.0
@BrianHenryIE
BrianHenryIE / log-order-status-change.php
Created November 15, 2020 22:09
Log WooCommerce order status changes with debug backtrace to determine what caused it.
<?php
/**
* When the status is set to processing, record what caused/initiated the change.
*
* Need in `wp-config.php`:
* define('WP_DEBUG', true);
* define('WP_DEBUG_LOG', true);
*
* @hooked woocommerce_order_status_changed
@BrianHenryIE
BrianHenryIE / unhook_wordpress_closure.php
Last active November 24, 2021 23:07
Unhook a closure from a WordPress action by using the class the closure binds to to compare.
<?php
/**
* Unhook a closure from a WordPress action by using the class the closure binds to to compare.
*/
$action_name = 'admin_notices';
$priority = 10;
$expected_class = MyClass::class;
<?php
class Maintenance_Redirect {
/**
* Exclude the Push Notifications for WordPress registration endpoint from redirection.
*
* @hooked wpjf3_matches
*
* @param array $wpjf3_matches List of reasons to disable redirection (not actually used anywhere, but array cannot be empty).
@BrianHenryIE
BrianHenryIE / bh_set_esig_super_admin.php
Created September 5, 2019 19:55
WP-E-Signature (Approve Me) admin permissions.
<?php
/**
* Sets/overwrites the super-admin user-id in the e-signature cache.
*
* Allows editing documents and saving documents as PDF,
* but not previewing documents in draft or viewing signed documents in the browser.
*/
function bh_set_esig_super_admin() {
/**