Skip to content

Instantly share code, notes, and snippets.

View xardit's full-sized avatar
🍀

Ardit Hyka xardit

🍀
View GitHub Profile
@xardit
xardit / functions.php
Created June 23, 2023 21:03
WP Hardcode Language Attribute on HEAD
<?php
// set language attribute of the main <html> tag hardcoded
function new_language_attributes($lang){
return "lang=\"it\"";
}
add_filter('language_attributes', 'new_language_attributes');
@xardit
xardit / functions.php
Created June 23, 2023 21:02
WP Change Language Attribute on HEAD based on specific slug
<?php
// set language attribute of the main <html> tag based on category value
function new_language_attributes($lang){
if(is_single()) {
$ar = get_the_category();
foreach($ar as $c) {
if($c->slug=='in-italiano') {
return "lang=\"it\"";
}
@xardit
xardit / functions.php
Created June 14, 2023 07:26
WP Woocommerce - Clear cart before adding new one
<?php
// clear cart before adding new one
add_filter( 'woocommerce_add_to_cart_validation', 'remove_cart_item_before_add_to_cart', 20, 3 );
function remove_cart_item_before_add_to_cart( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty() )
WC()->cart->empty_cart();
return $passed;
}
@xardit
xardit / function.php
Created June 7, 2023 21:41
WP Woocommerce - Redirect ADD TO CART > CHECKOUT PAGE for faster checkout
<?php
// redirect Add To Cart > Checkout
add_filter ('woocommerce_add_to_cart_redirect', function( $url, $adding_to_cart ) {
return wc_get_checkout_url();
}, 10, 2 );
@xardit
xardit / function.php
Created June 7, 2023 21:27
WP Woocommerce - Add "Cancel Order" button on Checkout page before place order, with action to Clear/Empty Cart and redirect to a referer page or wherever needed
<?php
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'custom_woocommerce_empty_cart_button' );
function custom_woocommerce_empty_cart_button() {
echo '<a href="/?empty_cart=yes" class="rq-btn rq-btn-transparent" title="' . esc_attr( 'Cancel Order', 'woocommerce' ) . '">' . esc_html( 'Cancel Order', 'woocommerce' ) . '</a>';
// echo '<a href="' . esc_url( '/cart' . add_query_arg( 'empty-cart', 'yes' ) ) . '" class="rq-btn rq-btn-transparent" title="' . esc_attr( 'Cancel Order', 'woocommerce' ) . '">' . esc_html( 'Cancel Order', 'woocommerce' ) . '</a>';
}
add_action( 'wp_loaded', 'custom_woocommerce_empty_cart_action', 20 );
function custom_woocommerce_empty_cart_action() {
@xardit
xardit / function.php
Created June 7, 2023 20:45
WooCommerce - Change return to shop link, send to homepage instead
<?php
add_filter( 'woocommerce_return_to_shop_redirect', 'mysite_change_return_shop_url' );
function mysite_change_return_shop_url() {
return home_url();
}
@xardit
xardit / head-section.html
Created November 29, 2022 22:32
CDN TAILWIND - You can easily test Tailwind Elements by adding CDN scripts to your classic HTML template without the need for installing any packages. Add the stylesheet files below in the head section:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tw-elements/dist/css/index.min.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
@xardit
xardit / vtt_to_srt.py
Created August 2, 2022 16:46
Convert subtitle VTT to SRT format
#!/usr/bin/python
"""Convert of vtt to srt format"""
import os
import re
import sys
from string import Template
from stat import S_ISDIR, ST_MODE, S_ISREG
@xardit
xardit / yup_validator_schema.ts
Created February 27, 2022 12:59
node yup validation schema example
import { string, number, object } from "yup";
// import { passwordResetRequestVerifyCode } from "./session.server";
const uuid = string().uuid("Gabim në identifikimin e linkut!");
const vatid = string().matches(
/^([a-z][0-9]{8,10}[a-z])$/gi,
"Numri NIPT është gabim! (Shembull X12345678X)"
);
const password = string().min(6).max(128);
const loginType = string().oneOf(
@xardit
xardit / WireGuard Setup
Last active July 17, 2024 00:35
Setting up WireGuard - Server and multiple Peers / Clients
Install WireGuard via whatever package manager you use. For me, I use apt.
# Ubuntu server install
$ sudo apt-get install wireguard
# MacOS client using brew
$ brew install wireguard-tools
Generate key your key pairs. The key pairs are just that, key pairs. They can be
generated on any device, as long as you keep the private key on the source and