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
<?php
// hide coupon field on cart page
function hide_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
@lmartins
lmartins / woo.php
Last active August 29, 2015 14:21
Notifies additional emails when a order is completed. By default this only notifies the Customer.
/*
* ----------------------------------------------------------------------------
* ADDS ANOTHER RECIPIENT TO COMPLETE ORDER EMAIL NOTIFICATION
* Permite que as notificações enviadas para o cliente sejam copiadas
* em BCC para outros destinatarios
* ----------------------------------------------------------------------------
*/
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 3);
@lmartins
lmartins / price.php
Created May 13, 2015 18:26
Show the sale savings percentage besides the product price and sale flash
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}
@lmartins
lmartins / woo.php
Created May 13, 2015 08:39
Customize variable woocommerce products price range label
/*
* Personalizar apresentacao do price range de produto
* para produtos variaveis
*/
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) $price .= '<span class="from">' . _x('From', 'min_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->min_variation_price);
return $price;
@lmartins
lmartins / woo.php
Last active November 30, 2015 18:25
Get the top level categories assigned to a product
function mw_theme_categories( $context )
{
$args = array( 'taxonomy' => 'product_cat' );
$terms = wp_get_post_terms( $context['post']->ID ,'product_cat', $args );
foreach ($terms as $cat) {
if($cat->parent == 0){
$out = '<div class="prodLabel prodLabel--' . strtolower( $cat->name ) . '">';
$out .= "<a href='/product-category/$cat->slug'>$cat->name</a>";
$out .= '</div>';
echo $out;
@lmartins
lmartins / gulpfile.js
Last active August 25, 2016 17:00
Gulpfile for basic Sass processing
var
gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer');
var config = {
dest: "./build",
src: "./src",
@lmartins
lmartins / SassMeister-input-HTML.html
Created February 28, 2015 14:27
Generated by SassMeister.com.
<div class="container">
<div class="col col01">col01</div>
<div class="col col02">
<div>col02</div>
<div class="col col02-1">col02-1</div>
<div class="col col02-2">col02-2</div>
</div>
<div class="col col03">col03</div>
</div>
@lmartins
lmartins / functions.php
Created January 16, 2015 19:37
Limit the excerpt lenght without truncating words
/**
* ----------------------------------------------------------------------------
* LIMITAR EXCERPT
* Limita o excerpt sem cortar palavras a meio
* http://wordpress.stackexchange.com/questions/70913/how-can-i-limit-the-character-length-in-excerpt
* ----------------------------------------------------------------------------
*/
function get_excerpt($limit, $source = null){
@lmartins
lmartins / installwp.sh
Last active September 6, 2015 21:45
Wordpress Install Plugins shell command Run with `sh installwp.sh`
#!/bin/sh
wp plugin install be-subpages-widget --activate
wp plugin install bulk-creator --activate
wp plugin install cookie-notice --activate
wp plugin install disable-comments --activate
wp plugin install jigsaw --activate
wp plugin install jetpack --activate
wp plugin install mailchimp --activate
wp plugin install mce-table-buttons --activate
wp plugin install menu-customizer --activate
/**
* A function to reorder the default display of fields on the WooCommerce Bookings form
* Put this function in your theme's functions.php file
*/
function custom_order_booking_fields ( $fields ) {
$reorder = array();
$reorder[] = $fields['wc_bookings_field_duration'];
$reorder[] = $fields['wc_bookings_field_resource'];
$reorder[] = $fields['wc_bookings_field_persons'];