Skip to content

Instantly share code, notes, and snippets.

View bmakowski's full-sized avatar

Bartek Makowski bmakowski

  • Poland, Bydgoszcz
View GitHub Profile
@bmakowski
bmakowski / functions.php
Last active October 25, 2016 11:34
WooCommerce hide shipping when Free shipping available
<?php
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
@bmakowski
bmakowski / functions.php
Last active October 25, 2016 11:35
WordPress redirect after logout
<?php
add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();') );
@bmakowski
bmakowski / custom-post-types.php
Created October 25, 2016 11:21
WordPress Custom Post Types Examples
<?php
/*
Example 1 - custom post type without category
Author: Bartek Makowski
*/
//inside wp-content/themes/{template}/functions.php
function create_post_type() {
@bmakowski
bmakowski / overriding-navigation-widget.php
Created October 25, 2016 11:29
WordPress Overriding default navigation widget to use walker
<?php
/*
Example 1 - overriding default navigation widget to use walker
Author: Bartek Makowski
*/
//inside wp-content/themes/{template}/functions.php
class LMU_WP_Nav_Menu_Widget extends WP_Nav_Menu_Widget{
<?php
/*
WP All Import DB Fix for showing incorrect users number
on WP Dashboard
Author: Bartek Makowski
*/
//inside main wordpress folder
@bmakowski
bmakowski / custom_placeholder_image.php
Created October 25, 2016 11:33
WooCommerce Custom Placeholder Image
<?php
/*
Custom Placeholder Image - shows when product hasn't got an image
Author: Bartek Makowski
*/
//inside wp-content/themes/{template}/functions.php
add_action('init', 'custom_fix_thumbnail');
@bmakowski
bmakowski / functions.php
Created October 28, 2016 11:58
WooCommerce Remove Shipping Tax from Order Total
<?php
function action_woocommerce_calculate_totals( ) {
global $woocommerce;
$woocommerce->cart->shipping_tax_total = 0;
};
add_action( 'woocommerce_calculate_totals', 'action_woocommerce_calculate_totals', 10, 1 );
@bmakowski
bmakowski / preg_match_domain_name.php
Last active December 13, 2017 16:15
Preg Match domain name
<?php
if( !preg_match('/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $domain) ){
// didn't match return error
return false;
}
@bmakowski
bmakowski / ragex.txt
Created January 17, 2018 02:52
Validate domain ragular expression
This allows only domains with "." for example "example.com"
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$
This allows also one-name domains like "localhost". "." is optional
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.?){1,126}(?!\d+)[a-zA-Z\d]{1,63}$