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 / supplant.js
Created August 29, 2014 07:25
Replace vars in a string with Javascript
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
};
// Usage
@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
// Force homelayout to fullwidth
add_action( 'genesis_meta', 'mw_do_homepage_layout' );
function mw_do_homepage_layout() {
if (is_home() || is_front_page()) {
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
}
}
@lmartins
lmartins / gist:c84fc899832cf7b560b7
Last active August 29, 2015 14:07 — forked from corsonr/gist:3ac30cc334cf344dbb3b
Change related products thumbnail size
<?php
add_filter( 'wp_head' , 'related_products_style' );
function related_products_style() {
if( is_product() ) :
?>
<style>
.woocommerce .related ul.products li.product, .woocommerce .related ul li.product, .woocommerce .upsells.products ul.products li.product, .woocommerce .upsells.products ul li.product, .woocommerce-page .related ul.products li.product, .woocommerce-page .related ul li.product, .woocommerce-page .upsells.products ul.products li.product, .woocommerce-page .upsells.products ul li.product {
width: 24% !important;
@lmartins
lmartins / gist:8a0643b32efd4592125e
Created October 8, 2014 07:40 — forked from corsonr/gist:ba033db9978a536b2b05
Show products weight in the cart process
<?php
// Store cart weight in the database
add_action('woocommerce_checkout_update_order_meta', 'woo_add_cart_weight');
function woo_add_cart_weight( $order_id ) {
global $woocommerce;
$weight = $woocommerce->cart->cart_contents_weight;
update_post_meta( $order_id, '_cart_weight', $weight );
}
@lmartins
lmartins / gist:cc13a804a7bcea1bd1b0
Created October 8, 2014 07:41 — forked from corsonr/gist:e5e5c5fc944c278049de
WooCommerce Subscriptions: edit sign-up button text
<?php
function woocommerce_custom_subscription_product_single_add_to_cart_text( $text = '' , $post = '' ) {
global $product;
if ( $product->is_type( 'subscription' ) ) {
$text = get_option( WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', __( 'Sign Up Now', 'woocommerce-subscriptions' ) );
} else {
$text = $product->add_to_cart_text(); // translated "Read More"
}
@lmartins
lmartins / gist:04f81dbad4246fd49d1e
Created October 8, 2014 07:43 — forked from corsonr/gist:9071214
WooCommerce - Store terms and conditions value within the database
<?php
/**
* Store terms and conditions value within the database
**/
add_action('woocommerce_checkout_update_order_meta', 'woo_save_terms_and_conditions_status');
function woo_save_terms_and_conditions_status( $order_id ) {
if ($_POST['terms']) update_post_meta( $order_id, '_terms', esc_attr($_POST['terms']));
}
@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 ) {
@lmartins
lmartins / front-page.php
Created October 8, 2014 08:44
WooCommerce custom loop for products on-sale
<?php
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
@lmartins
lmartins / front-page.php
Created October 8, 2014 08:44
WooCommerce custom loop for Featured Products
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 6
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
?>