Skip to content

Instantly share code, notes, and snippets.

@arioch1984
arioch1984 / no-shipping-methods-if-free-on.php
Last active August 29, 2015 14:17
Magento: remove other shipping methods if free is enabled. In app/ design/ frontend/ default/ YOURTEMPLATE/ template/ checkout/ onepage/ shipping_method/ available.phtml
<?php
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
$_shippingRateGroups = array('freeshipping' => $_shippingRateGroups['freeshipping']);
}
?>
@arioch1984
arioch1984 / add-to-sidebar.php
Last active August 29, 2015 14:15 — forked from nathanielks/add-to-sidebar.php
WP - Add to Sidebar
<?php
function cur_add_widget_to_sidebar( $widget_name, $add_to_sidebar, &$sidebar_options ){
$widget = get_option('widget_'.$widget_name);
if(!is_array($widget))$widget = array();
$count = count($widget)+1;
$sidebar_options[$add_to_sidebar][] = $widget_name.'-'.$count;
$widget[$count] = array();
update_option('widget_'.$widget_name,$widget);
@arioch1984
arioch1984 / wp_as_www.sh
Created February 17, 2015 10:40
WP cli as www-data user
#!/bin/bash
# $1 -> command to execute
WPPATH=$(pwd)
sudo -u www-data -i -- wp $@ --path=$WPPATH
@arioch1984
arioch1984 / scroll-to-anchor.js
Created February 13, 2015 10:21
JS - Scroll to anchor
function scrollToAnchor(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
}
scrollToAnchor('id3');
@arioch1984
arioch1984 / wp-print-hooks.php
Created January 22, 2015 10:51
Wordpress: Print hooks
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if ($_GET['instrument']=='hooks') {
@arioch1984
arioch1984 / cpt-field-change-from-child-theme-1.php
Last active August 29, 2015 14:11
Wordpress: Change CPT values from child theme
<?php
add_action('registered_post_type', 'custom_registered_post_type_handler', 10, 2);
function custom_registered_post_type_handler($post_type, $args) {
do_action("custom_registered_{$post_type}_post_type", $post_type, $args);
}
add_action('custom_registered_foo_post_type', 'custom_registered_foo_post_type_handler', 10, 2);
function custom_registered_foo_post_type_handler($post_type, $args) {
remove_action(current_filter(), __FUNCTION__, 10, 2); // only run once
// change your args here
@arioch1984
arioch1984 / wp-menu-dynamic-links.php
Created December 12, 2014 15:33
add dynamic links to wordpress menu voice urls
@arioch1984
arioch1984 / get-column-from-associative.php
Created December 12, 2014 14:30
Get column from associative array
<?php
function array_col(array $a, $x)
{
return array_map(function($a) use ($x) { return $a[$x]; }, $a);
}
?>
@arioch1984
arioch1984 / max-from-associative-array-column.php
Last active August 29, 2015 14:11
max value from a column of associative array
<?php
function array_col(array $a, $x)
{
return array_map(function($a) use ($x) { return $a[$x]; }, $a);
}
$max = max(array_col($menu_items, 'colonna'));
?>
@arioch1984
arioch1984 / new_gist_file.php
Last active August 29, 2015 14:10
Programmatically create category
<?php
try{
$category = Mage::getModel('catalog/category');
$category->setName('check');
$category->setUrlKey('new-category');
$category->setIsActive(1);
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor(1); //for active achor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);