Skip to content

Instantly share code, notes, and snippets.

@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
@esedic
esedic / uk_comp.js
Created April 11, 2025 09:21
Uikit Custom Component Example
(function (UIkit) {
if (!UIkit) {
throw new Error('UIkit not found. Make sure UIkit is loaded before this plugin.');
}
UIkit.component('floating-label', {
connected() {
this.initFloatingLabel();
},
methods: {
@esedic
esedic / yt.php
Created March 16, 2025 16:58
Get Youtube video ID from a string with PHP
<?php
abstract class Helper {
public static function getVidId($text) {
if(preg_match('~(?:https?://)?(?:www.)?(?:youtube.com|youtu.be|youtube-nocookie.com)/(?:watch\?v=|embed/)?([^"\?\s]+)~', $introtext, $match)) {
return $match[1]; //
}
}
}
@esedic
esedic / toolbar.less
Created March 12, 2025 16:38
Yootheme - Display Toolbar on Mobile
// YOOtheme > SETTINGS > Custom Code > CSS/LESS:
@media(max-width: @breakpoint-medium-max) {
.tm-toolbar.uk-visible\@m {
display: block !important;
order: -1;
}
.tm-page {
display: flex;
flex-direction: column;
@esedic
esedic / email.php
Created February 24, 2025 11:33
Customizing WordPress User Registration Email
<?php
function custom_registration_email($user_id) {
$user_info = get_userdata($user_id);
$to = $user_info->user_email;
$subject = 'Welcome to our site!';
$message = 'Dear ' . $user_info->display_name . ',<br /><br />';
$message .= 'Thank you for registering on our site. Here is your login information:<br />';
$message .= 'Username: ' . $user_info->user_login . '<br />';
$message .= 'Password: Your chosen password<br /><br />';
@esedic
esedic / config.php
Created February 21, 2025 17:27
Add widget position in Yootheme Pro
<?php
// Create a file config.php with this code in put in child theme
return [
// Set theme configuration values
'theme' => [
'positions' => [
'header-top' => 'Header Top',