Skip to content

Instantly share code, notes, and snippets.

View lmartins's full-sized avatar

Luis Martins lmartins

  • Goodwin Media, Multiweb
  • Portugal
View GitHub Profile
//* Add walker class that displays menu item descriptions
class Menu_With_Description extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
@lmartins
lmartins / functions.php
Created November 25, 2014 09:46
Call wordpress menus with Shortcode via menu slug
/**
* MENU SHORTCODE
* Display any menu using the menu slug
*/
function print_menu_shortcode($atts, $content = null) {
extract(shortcode_atts(array( 'name' => null, ), $atts));
return wp_nav_menu( array( 'menu' => $name, 'echo' => false ) );
}
add_shortcode('menu', 'print_menu_shortcode');
@lmartins
lmartins / functions.php
Created November 24, 2014 18:09
Change WooCommerce shipping and taxes notice in Cart Page
add_action( 'init', 'mw_gettext_filter_woocommerce', 9999 );
/**
* Change the text in WooCommerce for "Shipping and taxes are estimated..." via Gettext filter.
*
* @author David Decker - DECKERWEB
* @link http://twitter.com/deckerweb
*/
function mw_gettext_filter_woocommerce() {
add_filter( 'gettext', 'ddw_woocommerce_change_estimated_shipping_taxes_text', 9999, 2 );
@lmartins
lmartins / increase-specificity.scss
Last active August 29, 2015 14:10 — forked from barneycarroll/increase-specificity.scss
Increase selector specificity
// Increase class-level specificity of a rule without functionaly modifying the selector
@mixin increase-specificity( $depth: 1 ) {
$sel : '';
@while($depth > 0) {
$sel : $sel + ':nth-child(n)';
$depth : $depth - 1;
}
&#{$sel} {
@lmartins
lmartins / widgets.php
Created November 22, 2014 12:39
Adds a widget area to the layout including a overall widgets wrapper
add_action( 'genesis_before_loop', 'mw_genesis_after_header_sidebars' );
function mw_genesis_after_header_sidebars()
{
genesis_widget_area( 'utilities-header', array(
'before' => '<div class="widget-area utilities-header">',
'after' => '</div>',
) );
}
@lmartins
lmartins / woo-cartcheckout.php
Created November 21, 2014 16:19
Disable payment method for certain countries
/**
* Desabilita pagamento por Transferência para clientes não PT
*/
function mw_payment_gateway_disable_country( $available_gateways )
{
global $woocommerce;
if ( isset( $available_gateways['bacs'] ) && $woocommerce->customer->get_country() !== 'PT' ) {
unset( $available_gateways['bacs'] );
}
@lmartins
lmartins / functions.php
Last active November 3, 2023 19:28 — forked from woogist/functions.php
By default WooCommerce redirects the user to the My Account page after a successful login. You may change this and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers. To do this, add this code at the end of the file functions.php located in wp-content/themes/your-theme-name/ https://support.w…
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
@lmartins
lmartins / gulpfile.js
Last active August 25, 2016 17:00
Current Gulpfile configuration
'use strict';
var gulp = require('gulp'),
connect = require('gulp-connect'),
gulpLoadPlugins = require('gulp-load-plugins'),
cleanhtml = require('gulp-cleanhtml'),
dev = require('gulp-dev'),
browserSync = require('browser-sync'),
plugins = gulpLoadPlugins(),
webpack = require('webpack'),
@lmartins
lmartins / genesis_attr_add_class.php
Last active September 20, 2022 13:33 — forked from JiveDig/genesis_attr_add_class.php
Add classes and attributes to any element in Genesis
<?php
//* Add class to .site-container
add_filter('genesis_attr_site-container', 'jive_attributes_st_container');
function jive_attributes_st_container($attributes) {
$attributes['class'] .= ' st-container';
return $attributes;
}
//* Add class to .site-inner
@lmartins
lmartins / woo-archives.php
Created November 18, 2014 19:24
Show categories associated to each product in archives
/**
* Mostra as categorias associadas ao tema
*/
add_action( 'woocommerce_after_shop_loop_item_title', 'mw_archive_add_theme_category', 5 );
function mw_archive_add_theme_category()
{
global $product;
$out = '<div class="product-categories">';
$out .= strip_tags( $product->get_categories() );