Skip to content

Instantly share code, notes, and snippets.

@esedic
esedic / scroll.js
Created October 10, 2025 09:38
Add an offset to scrolling anchor links
// Method 1
window.addEventListener('load', function() {
var theHash = location.hash;
// add offset only for specific hashes
var hashes = ['#project-togo', '#project-colombia-visajes', '#project-colombia-izquierdo', '#project-yemen', '#project-tansania'];
if (hashes.includes(theHash)) {
window.scrollBy(0, -100);
}
});
@esedic
esedic / wcgeo.php
Created September 30, 2025 16:35
Uses WooCommerce geolocation method
<?php
// Get current user's location
$geo_data = WC_Geolocation::geolocate_ip();
$country = $geo_data['country'];
$state = $geo_data['state'];
// Use a specific IP address
$location = WC_Geolocation::geolocate_ip( '8.8.8.8' );
@esedic
esedic / url.php
Created September 25, 2025 09:05
Get Current URL in Joomla 3 with PHP
<?php
// Method 1: Using JUri (Recommended)
// Get the full current URL
$currentUrl = JUri::getInstance()->toString();
// Get only the base URL (without query parameters)
$baseUrl = JUri::base();
// Get the current URI path
@esedic
esedic / content-product.php
Created August 21, 2025 11:54
WooCommerce template override
<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-product.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
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@esedic
esedic / wp-polylang-breadcrumb-navxt.php
Created July 22, 2025 08:42
Fix home page URL for non-default languages Breadcrumb NavXT and Polylang
<?php
add_action('bcn_after_fill', function($bcn_breadcrumb_trail){
foreach ($bcn_breadcrumb_trail->breadcrumbs as $index => $value){
if(in_array('home',$bcn_breadcrumb_trail->breadcrumbs[$index]->get_types())){
$bcn_breadcrumb_trail->breadcrumbs[$index]->set_url( pll_home_url());
}
}
});
@esedic
esedic / fetch.js
Created June 19, 2025 07:22
Using Fetch API for Ajax Requests
// GET Request:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Failed to fetch data', error));
// POST Request:
fetch('https://api.example.com/data', {
method: 'POST',
@esedic
esedic / wc_block.php
Created June 17, 2025 12:32
Detecting WooCommerce Block Pages
<?php
function is_wc_cart_block_based() {
$cart_page_id = wc_get_page_id( 'cart' );
if ( $cart_page_id && $cart_page = get_post( $cart_page_id ) ) {
// Check for WooCommerce Cart block
return has_block( 'woocommerce/cart', $cart_page );
}
return false;
}
@esedic
esedic / estimate.php
Created May 12, 2025 09:30
Show estimated shipping time on WooCommerce product pages
<?php
/*
* Plugin Name: WooCommerce Shipping Time Display
* Plugin URI: https://wcwiz.com/how-to-show-shipping-time-on-woocommerce-product-page/
* Description: Adds a custom shipping time field to WooCommerce products and displays it on the product page.
* Version: 1.9
* Author: Shameem Reza
* Author URI: https://shameem.dev
* License: GPL2
* Text Domain: wc-shipping-time
@esedic
esedic / wp_cf_search.php
Created April 25, 2025 09:35
Including custom fields in WordPress search
<?php
// Source: https://wordpress.stackexchange.com/questions/414404/how-to-include-custom-fields-in-wordpress-search/414408#414408
function include_custom_field_in_search($query) {
if ($query->is_search) {
$query->set('meta_query', array(
array(
'key' => 'release_year',
'value' => $query->query_vars['s'],
'compare' => 'LIKE'
@esedic
esedic / backup.txt
Created April 15, 2025 13:53
SSH files backup
tar -czvf - --exclude='mydomain.com/administrator/backups' /var/www/sites/mydomain.com > /local/backup/mydomain_backup.tar.gz