Skip to content

Instantly share code, notes, and snippets.

View mrkkr's full-sized avatar

Marek mrkkr

  • Poland
View GitHub Profile
@mrkkr
mrkkr / Change number of product displayed on archive-product.php
Last active April 16, 2018 08:49
Change number of product displayed on archive-product #php
<?php
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 50;
return $cols;
}
@mrkkr
mrkkr / reponsive_google_maps.css
Created April 11, 2018 10:05
Responsive google maps container
.map-responsive{
overflow:hidden;
padding-bottom:56.25%;
position:relative;
height:0;
}
.map-responsive iframe{
left:0;
top:0;
height:100%;
@mrkkr
mrkkr / async_script_wordpress.php
Created April 16, 2018 08:48
How to add async tag to script in Wordpress #php
///in functions.php
<?php
function add_async_attribute($tag, $handle) {
if ( 'SCRIPT_NAME' !== $handle )
return $tag;
return str_replace( ' src', ' async src', $tag );
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
@mrkkr
mrkkr / css_hacks_firefox_ie_edge.css
Created April 18, 2018 08:13
CSS hacks for Firefox, IE10+, Edge #css
@-moz-document url-prefix() {
/* Firefox (all) */
}
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}
@supports (-ms-ime-align:auto) {
/* IE Edge 12+ CSS styles go here */
}
@mrkkr
mrkkr / object_fit_carousel_ie_hack.css
Created April 18, 2018 10:04
CSS object-fit IE hack (carousel) #html #css #js
@mrkkr
mrkkr / display_username_when_loggedin.php
Last active April 25, 2018 09:59
Show user name when is logged in Wordpress #php
<?php
function show_username_when_login() {
global $current_user;
if ( is_user_logged_in() ) {
return $current_user->display_name;
} else {
return 'Log In';
}
@mrkkr
mrkkr / display_woo_cart_item_with_total_amount.php
Created April 25, 2018 10:02
Display Woocommerce cart item amount and total amount #php
<?php
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php).
// Used in conjunction with https://gist.github.com/woogists/9a16fd2d0c982e780a5de89c30cbbd25
// Compatible with WooCommerce 3.0+. Thanks to Alex for assisting with an update!
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
@mrkkr
mrkkr / add_custom_items_to_wp_menu.php
Created April 25, 2018 12:08
Add custom items to menu in Wordpress #php
<?php
/* add custom items to primary menu */
add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);
function add_search_box_to_menu( $items, $args ) {
if( $args->theme_location == 'primary' ) /* ID of menu */
return $items.'CUSTOM THINGS';
return $items;
}
@mrkkr
mrkkr / hide_default_woo_cat_from_widget.php
Created April 25, 2018 12:18
Hide default woocommerce category from product category widget #php
<?php
/* hide uncategorized product category */
add_filter( 'woocommerce_product_categories_widget_args', 'custom_woocommerce_product_subcategories_args' );
function custom_woocommerce_product_subcategories_args( $args ) {
$args['exclude'] = get_option( 'default_product_cat' );
return $args;
}
@mrkkr
mrkkr / woo_dropdown_product_tag_filter.php
Last active April 26, 2018 11:50 — forked from dustyf/gist:5862035
Woo Commerce Dropdown to filter product tag within an archive page.
<?php
function displayLocationDropdown() {
$html = '';
$html .= '<form class="location-select" method="post">';
$html .= '<select id="location-selector" name="location" class="location">';
$tag = wp_tag_cloud( array(
'format' => 'array',