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
@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 / template-test.php
Last active April 11, 2019 00:59 — forked from billerickson/template-test.php
Genesis Custom Loop
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_custom_loop() {
global $post;
// arguments, adjust as needed
@lmartins
lmartins / upload-a-file.MD
Created January 2, 2019 14:35 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@lmartins
lmartins / gulpfile.js
Last active September 2, 2018 17:08 — forked from anonymous/gulpfile.js
Show sass compilation errors in the browser
var gulp = require("gulp");
var sass = require("gulp-sass");
var autoprefix = require("gulp-autoprefixer");
var filter = require('gulp-filter');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
/**
* Start BrowserSync
*/
@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;
@lmartins
lmartins / gist:cdafd234879acf5e2160
Created October 8, 2014 07:45 — forked from corsonr/gist:7370707
WooCommerce - display order coupons used in confirmation email and edit order page
add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );
/**
* Add used coupons to the order confirmation email
*
*/
function add_payment_method_to_admin_new_order( $order, $is_admin_email ) {
if ( $is_admin_email ) {
<div>
<label for="sort-by">Sort by</label>
<select id="sort-by">
<option value="manual">Featured</option>
<option value="price-ascending">Price: Low to High</option>
<option value="price-descending">Price: High to Low</option>
<option value="title-ascending">A-Z</option>
<option value="title-descending">Z-A</option>
<option value="created-ascending">Oldest to Newest</option>
<option value="created-descending">Newest to Oldest</option>
@lmartins
lmartins / related-products.liquid
Created November 16, 2017 11:29 — forked from carolineschnapp/related-products.liquid
Related Products — to add to product.liquid