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 / letter-post-list.php
Last active February 22, 2017 19:24
Letter post list
<?php
$posts = get_posts([
'post_status' => 'publish',
'posts_per_page' => -1,
'post_type' => 'post'
]);
$post_index = array_fill_keys( array_merge( [ '#' ], range( 'a', 'z' ), ['å', 'ä', 'ö', ] ), [] );
foreach( $posts as $post ) {
$first_letter = strtolower( substr( $post->post_title, 0, 1 ) );
@pelmered
pelmered / wp-config.php
Created February 27, 2017 20:56
Fix issues with symlinked wordpress
<?php
/**
* Fixes issues with symlinked wordpress
*/
if ( defined('ABSPATH') ) {
$fixed_abspath = str_replace( 'wordpress', 'public', ABSPATH );
define('WP_CONTENT_DIR', $fixed_abspath . 'wp-content');
define('WP_PLUGIN_DIR', $fixed_abspath . 'wp-content/plugins');
}
@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`;
@pelmered
pelmered / hide-when-free-avaialble.php
Last active September 4, 2017 14:52
Hide other shipping methods except local delivery when “Free Shipping” is available
/**
* Hide shipping rates except local delivery when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
$local_pickup = array();
@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 / composer.json
Created October 9, 2015 17:14
Example composer.json for WordPress
{
"repositories": [
{
"type": "composer",
"url": "http://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
@pelmered
pelmered / convert-to-composer.php
Last active March 20, 2018 14:03
Convert WP to Composer
#!/usr/bin/php
<?php
/**
* USAGE:
*
* (optional) Download script:
* "wget https://gist.githubusercontent.com/pelmered/2ee27f1cb18b8c73a0205ded580e3195/raw/convert-to-composer.php"
*
* Basic usage:
* php convert-to-composer.php
@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 / wp-config.php
Created November 13, 2018 14:47
WordPress debug
<?php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@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 != "") {