Skip to content

Instantly share code, notes, and snippets.

View pelmered's full-sized avatar
🎯
Focusing

Peter Elmered pelmered

🎯
Focusing
View GitHub Profile
@pelmered
pelmered / gist:9d9652688c4215700794
Last active August 29, 2015 13:55
Replace fullsize image when thumbnail is clicked in WooCommerce/Wordpress
jQuery(function($){
$('.thumbnails>a>img').click(function(e){
e.stopPropagation();
$('.woocommerce-main-image img').attr('src', $(this).attr('src').replace('-87x87','-564x564'));
return false;
});
});
@pelmered
pelmered / WooCommerce-custom-product-count.php
Last active August 29, 2015 14:03
WooComemrce: Change number or products
//Set products per row
add_filter( 'loop_shop_columns', create_function( '$cols', 'return 3;' ), 20 );
//Set products per page
add_filter( 'loop_shop_per_page', create_function( '$num', 'return 12;' ), 20 );
@pelmered
pelmered / gist:20718fd4162be0df32d7
Created July 11, 2014 14:14
Stackoverflow #24573343
$product_ids_raw = $wpdb->get_results(
"SELECT wp_posts.ID, wp_posts.post_parent
FROM wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE
wp_posts.post_status = 'publish'
AND (mt1.meta_key = '_sale_price_dates_to' AND mt1.meta_value >= ".time().")
GROUP BY wp_posts.ID
@pelmered
pelmered / gist:76830d0b283a09548bfb
Last active August 29, 2015 14:11
Color of first word in WordPress content
add_filter('the_content', 'set_first_word_color', 10);
function set_first_word_color( $content )
{
$color = '#FF0000';
$pos = strpos(ltrim($content), ' ');
$new_content = '<span style="color: '.$color.'"'.substr($content, 0, $pos).'</span>'.substr($content, $pos);
<?php
/**
* Gets the current global post type if one is set
*/
function x_get_current_post_type() {
global $post, $typenow, $current_screen;
if( $post && $post->post_type )
$post_type = $post->post_type;
elseif( $typenow )
@pelmered
pelmered / plugin.php
Created June 12, 2015 15:25
Allow template to override plugin templates
function include_template( $template, $args = array() )
{
//Allow plugins to manipulate the tempalte data before sending it to the template
$data = apply_filters('prefix_template_data', $args, $template);
//Look in theme folder first, then plugin folder
if(locate_template($template) === '')
{
include PREFIX_PLUGIN_PATH . 'templates/' . $template;
//
// Improved and much cleaner version of https://gist.github.com/andyl/6360906
//
//
// Bootstrap Mid-Small - col-ms-* - the missing grid set for Bootstrap3.
//
// This is a hack to fill the gap between 480 and 760 pixels - a missing range
// in the bootstrap responsive grid structure. Use these classes to style pages
// on cellphones when they transition from portrait to landscape.
//
@pelmered
pelmered / wp-db-backup.sh
Last active August 29, 2015 14:26
WP-CLI snippets and scripts
# Only database backup
declare -a SITES=('site1' 'site2' 'site3' 'site4');
SITES_PATH_BASE=/var/www/
SITES_PATH_SUFIX=/repo/public
SITES_BACKUP_FOLDER=backups
CURRENT_DATE=`date +%Y-%m-%d`;
@pelmered
pelmered / functions.php
Last active September 6, 2015 12:23
Add info link based on product category [WooCommerce]
<?php
add_action( 'woocommerce_single_product_summary', 'my_add_read_more_about_category', 25);
function my_add_read_more_about_category()
{
global $product;
$cat_post_map = array(
// category id => array(<page id to link to>, <category plural label (optional)>)
@pelmered
pelmered / taxonomies.php
Last active January 4, 2016 16:49
Create taxonomy with rewrite with Post types creator https://github.com/pelmered/post-types-creator
<?php
if( class_exists( 'PE_Post_Type_Creator' ) )
{
$ptc = new PE_Post_Type_Creator();
$text_domain = 'text-domain';
$ptc->set_taxonomies(array(
'min-taxonomi' => array(
'singular_label' => _x('Min taxonomi', 'Post type plural', $text_domain),