Skip to content

Instantly share code, notes, and snippets.

@andrejarh
andrejarh / woocommerce_events.md
Created January 14, 2023 11:25 — forked from mpdevcl/woocommerce_events.md
WooCommerce JS Events

WooCommerce JS Events

Source

Checkout

$( document.body ).trigger( 'init_checkout' );
$( document.body ).trigger( 'payment_method_selected' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_checkout' );
$( document.body ).trigger( 'checkout_error' );
@andrejarh
andrejarh / gist:6d9cbe68409470a124d3261761edea51
Created October 19, 2022 16:29 — forked from tott/gist:2572405
debugging WordPress rewrite rules
<?php
add_action( 'generate_rewrite_rules', 'debug_action_generate_rewrite_rules', 1, 1 );
// debug http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L1592
// this should only be hit if the rewrite_rules option is empty.
// http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L1616
function debug_action_generate_rewrite_rules( $rules ) {
global $debug_action_rules;
error_log( __FUNCTION__ . ' : ' . __LINE__ );
error_log( var_export( $_SERVER, true ) );
error_log( "Rules Option: " . var_export( get_option( 'rewrite_rules' ), true ) );
@andrejarh
andrejarh / gist:af7c3f87c5a9866c55f6a4776d47e796
Created October 19, 2022 12:03 — forked from yunusga/gist:33cf0ba9e311e12df4046722e93d4123
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
@andrejarh
andrejarh / log all jQuery events
Created May 21, 2020 09:06 — forked from kirkonrails/log all jQuery events
Log all jQuery events to console via redfine jquery trigger
var oldJQueryEventTrigger = jQuery.event.trigger;
jQuery.event.trigger = function( event, data, elem, onlyHandlers ) {
console.log( event, data, elem, onlyHandlers );
oldJQueryEventTrigger( event, data, elem, onlyHandlers );
}
define('WP_DEBUG', true);
ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
define('SCRIPT_DEBUG', true);
@andrejarh
andrejarh / example-ajax-enqueue.php
Created February 28, 2020 10:37 — forked from devinsays/example-ajax-enqueue.php
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array('jquery')
);
@andrejarh
andrejarh / metabox-repeatable-fields.php
Created February 25, 2020 10:20 — forked from ashokmhrj/metabox-repeatable-fields.php
Repeating Custom Fields with Image Uploading and drag n drop in a Metabox
<?php
/**
* Repeatable Custom Fields in a Metabox with Image upload
* Drag and Drop option
* Modified by: ashokmhrj
* Extracted from: Helen Hou-Sandi
*/
define('PATH_TO_JS','define path here');
function ask_admin_repeater_script(){
@andrejarh
andrejarh / functions.php
Created January 7, 2020 13:58
Move hamburger menu on the top-left. Applicable for Dentalia and Recycle theme
/*copy the following snippet to Theme Options -> Custom CSS */
@media (max-width: 991px) {
.to-x .hamburger-box {
display: table-cell;
}
.to-x {
position: absolute!important;
top: 0;
left: 0;
@andrejarh
andrejarh / WordPress Repeater MetaBox
Created December 19, 2019 13:05 — forked from akshuvo/WordPress Repeater MetaBox.php
Creating a “repeater meta-box” without a Plugin in WordPress
<?php
add_action('admin_init', 'gpm_add_meta_boxes', 2);
function gpm_add_meta_boxes() {
add_meta_box( 'gpminvoice-group', 'Custom Repeatable', 'Repeatable_meta_box_display', 'page', 'normal', 'default');
}
function Repeatable_meta_box_display() {
global $post;
$gpminvoice_group = get_post_meta($post->ID, 'customdata_group', true);
@andrejarh
andrejarh / functions.php
Last active October 18, 2019 13:46 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field