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 / party.sh
Created September 19, 2014 12:09
Best shell script ever
#!/bin/bash
while :
do
eject
eject -t
done
@pelmered
pelmered / gist:a9e725cb0b712aeac24a
Last active July 4, 2018 10:33
Override price based on group/role of logged in user
add_filter('woocommerce_get_sale_price', 'my_custom_price', 99, 2);
add_filter('woocommerce_get_price', 'my_custom_price', 99, 2);
function my_custom_price( $price, $product )
{
//your logic for calculating the new price here
//Half price for VIP-customers
if( in_array('vip', get_userdata(get_current_user_id())->roles )
@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);
@pelmered
pelmered / gist:9593f6ca25a84a7ce962
Last active April 2, 2017 21:44
Remove and reset all products and categories in magento
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
<?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 / purchasable-by-category.php
Last active December 22, 2017 18:11
Make WooCommerce products purchasable by category
add_action('wp', 'prefix_theme_setup', 99);
function prefix_theme_setup()
{
add_filter( 'woocommerce_is_purchasable', 'prefix_is_purchasable', 20, 2);
}
function prefix_is_purchasable($purchasable, $product)
@pelmered
pelmered / wpfcwc.conf
Created March 27, 2015 08:56
EasyEngine WooCommerce config with FastCGI Cache
#
set $skip_cache 0;
# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {