Skip to content

Instantly share code, notes, and snippets.

@bagerathan
bagerathan / customize-wp-login.php
Created July 29, 2020 04:46
Customize WordPress login page
function oo_custom_login_logo() {
?>
<style type="text/css">
body.login{
background: #1D1D1D;
}
body.login p#backtoblog{
display: none;
}
body.login p#nav a,
@bagerathan
bagerathan / woo-events.js
Last active October 28, 2024 06:19
[Woocommerce Javascript events] #woo
//Woocommerce Checkout JS events
$( 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' );
//Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' );
$( document.body ).trigger( 'update_checkout' );
@bagerathan
bagerathan / remove-products.sql
Last active August 22, 2021 15:18
[Remove all products, categories, meta and relations] #woo
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@bagerathan
bagerathan / group-terms.php
Created August 11, 2020 10:39
Group taxonomy terms alphabetically
/**
* Snippet Name: List taxonomies by initial letter
* Snippet URL: http://www.wpcustoms.net/snippets/list-taxonomies-by-initial-letter/
*/
$list = '';
$args = array(
'hide_empty' => true,
);
$tags = get_terms('CUSTOM-TAXONOMY',$args);
@bagerathan
bagerathan / svg-background.css
Last active August 24, 2021 05:22
[SVG in background] #css #svg
body {
background-image:
url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><linearGradient id='gradient'><stop offset='10%' stop-color='%23F00'/><stop offset='90%' stop-color='%23fcc'/> </linearGradient><rect fill='url(%23gradient)' x='0' y='0' width='100%' height='100%'/></svg>");
}
/*
Note that the SVG content needs to be url-escaped for this to work, e.g. # gets replaced with %23.
*/
@bagerathan
bagerathan / video-thumbnails.php
Created September 10, 2020 11:21
Get video thumbnails
//return thumbnail for youtube and vimeo
function video_image($url){
$image_url = parse_url($url);
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com'){
$array = explode('&', $image_url['query']);
return 'http://img.youtube.com/vi/'.substr($array[0], 2).'/0.jpg';
} else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com'){
$hash = unserialize(curl_get_file_contents('http://vimeo.com/api/v2/video/'.substr($image_url['path'], 1).'.php'));
return $hash[0]['thumbnail_small'];
}
@bagerathan
bagerathan / change-woo-order-status.php
Created October 22, 2020 12:20
Change order status #woo
add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
function wc_auto_complete_paid_order( $status, $order_id, $order ) {
return 'completed';
}
@bagerathan
bagerathan / loop.scss
Last active August 21, 2021 04:58
[Loop for preprocessors] #css #sass #less
//https://css-tricks.com/how-to-write-loops-with-preprocessors/
//for
@for $i from 1 through 15 {
div {
&:nth-child(#{$i}) {
&::after {
content: "#{$i}";
}
}
@bagerathan
bagerathan / disable-theme-plugins.php
Last active August 22, 2021 15:19
[Disable a plugin or theme upgrade] #wp
function disable_unnecessary_notification( $value ) {
if ( isset( $value ) && is_object( $value ) ) {
unset( $value->response['Impreza'] );
}
return $value;
}
add_filter( 'site_transient_update_themes', 'disable_unnecessary_notification' );
function filter_plugin_updates( $value ) {
unset( $value->response['facetwp/index.php'] );
@bagerathan
bagerathan / change-tax.php
Last active August 21, 2021 04:57
[Change tax amount based on billing or shipping address] #woo
billing_wcj_checkout_field_1
<?php
add_action('woocommerce_after_checkout_form', function($checkout){
?>
<script type="text/javascript">
jQuery(function($){
$(document).on('change','#billing_wcj_checkout_field_1',function(){
$(document.body).trigger("update_checkout");