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 / 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 / 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 / remove-gutenburg-blocks.php
Last active August 21, 2021 04:55
[remove core blocks] #wp #gutenburg
add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
function misha_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
@bagerathan
bagerathan / disable-gateway-for-country.php
Last active August 21, 2021 04:56
[Disable gateway for certain country] #woo
add_filter( 'woocommerce_available_payment_gateways', 'rudr_gateway_by_country' );
function rudr_gateway_by_country( $gateways ) {
if( is_admin() ) {
return $gateways;
}
if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page
@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");
@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 / edit-checkout-form.php
Created August 21, 2021 13:37
[Edit checkout form] #woo
//source: https://www.cloudways.com/blog/how-to-edit-delete-fields-and-email-in-woocommerce-custom-checkout-fields/
//remove first name and last name.
function woocommerce_remove_additional_information_checkout($fields){
unset( $fields["billing_first_name"] );
unset( $fields["billing_last_name"] );
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'woocommerce_remove_additional_information_checkout' );
@bagerathan
bagerathan / wp-config.php
Created August 21, 2021 14:24
[wp-config customisations] #wp
//difine default theme
define( 'WP_DEFAULT_THEME', 'default-theme-folder-name' );
//diable autoupdate
define( 'AUTOMATIC_UPDATER_DISABLED', true );
//only disable core updates
define( 'WP_AUTO_UPDATE_CORE', false )
//enable trash for media