Skip to content

Instantly share code, notes, and snippets.

View xardit's full-sized avatar
🍀

Ardit xardit

🍀
  • Space
View GitHub Profile
@xardit
xardit / functions.php
Created July 4, 2023 12:26
WP Custom Upload MIME types
<?php
function my_custom_mime_types( $mimes ) {
// New allowed mime types.
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
$mimes['doc'] = 'application/msword';
// Optional. Remove a mime type.
unset( $mimes['exe'] );
@xardit
xardit / functions.php
Created June 30, 2023 13:17
WP Disable XMLRPC via functions
<?php
// disable xmlrpc
add_filter( 'xmlrpc_enabled', '__return_false' );
@xardit
xardit / script.js
Created June 25, 2023 17:21
WhatsApp Icon Floating in Javascript
(function(d) {
var phone = '+1234567';
var text = "Hello, I'm interested for: " + window.location.href;
if(!window.location.pathname.startsWith("/products")){
text = "Hello, I'm interested..";
}
var link = d.createElement('a');
var style = d.createElement('style');
@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'],