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
/**
* Get post image.
*/
function wds_get_post_image( $size = 'thumbnail' ) {
// If featured image is present, use that
if ( has_post_thumbnail() ) {
return get_the_post_thumbnail( $size );
<?php
/**
* Get post image.
*/
function wds_get_post_image( $size = 'thumbnail' ) {
// Check for featured image
if ( has_post_thumbnail() ) {
the_post_thumbnail( $size );
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@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 / 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 / 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 / filter-genesis-structural-wrap.php
Last active August 29, 2015 14:09 — forked from calliaweb/filter-genesis-structural-wrap.php
Add additional content before/after Genesis structural elements
<?php
//* Do NOT include the opening php tag
add_filter( "genesis_structural_wrap-footer-widgets", 'jmw_filter_footer_widgets_structural_wrap', 10, 2);
/**
* Filter the footer-widgets context of the genesis_structural_wrap to add a div before the closing wrap div.
*
* @param string $output The markup to be returned
* @param string $original_output Set to either 'open' or 'close'
*/
@lmartins
lmartins / gist:37e021fa92464b791806
Last active August 29, 2015 14:08 — forked from corsonr/gist:8703820
Removes the "shop" title on the main shop page
<?php
add_filter( 'woocommerce_show_page_title' , 'woo_hide_page_title' );
/**
* woo_hide_page_title
*
* Removes the "shop" title on the main shop page
*
* @access public
@lmartins
lmartins / gist:9234b5983b62e66fc87d
Last active February 23, 2018 19:49 — forked from bryceadams/gist:a8e01ad4e1901f849658
Quick little snippet that will let you add a static PDF file (or in fact, any kind of file) to the WooCommerce Order Emails. Just add the following code to the ‘custom functions’ area of your functions.php file:
<?php
// http://bryceadams.com/add-pdf-woocommerce-order-email/
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments, $status , $order ) {
$allowed_statuses = array( 'new_order', 'customer_invoice', 'customer_processing_order', 'customer_completed_order' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$your_pdf_path = get_template_directory() . '/terms.pdf';
$attachments[] = $pdf_path;