Skip to content

Instantly share code, notes, and snippets.

View cobbman's full-sized avatar
🏠
Working Remotely

William cobbman

🏠
Working Remotely
View GitHub Profile
@cobbman
cobbman / functions.php
Last active May 30, 2018 18:14
WooCommerce - Show min - max prices for variations, rather than the min price only
/**
* This code should be added to functions.php of your theme
**/
//This changes the "From:" price on the products page to a Rent-Buy value instead.
// ***** It ALSO checks to see if the product is on sale, and displays the sale price instead of the top variable price
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
@cobbman
cobbman / MagentoCategory.phtml
Last active December 14, 2015 07:39
Display category name and id in Magento phtml file
echo $_category->getName().'|'.$_category->getId();
@cobbman
cobbman / layout.xml
Last active December 14, 2015 07:39
Adding a CMS Static Block to your XML file. xml layout files are located under app/design/default/<your-theme>/layout/
<cms_index_index>
<reference name="content">
<block type="cms/block" name="static_block_name" before="-">
<action method="setBlockId"><block_id>static_block_name</block_id></action>
</block>
</reference>
</cms_index_index>
notes:
<cms_index_index> tells it to only show up on the front page
@cobbman
cobbman / dynamicNavigation.js
Last active December 14, 2015 07:59
jQuery: Highlight current navigation element. Useful for highlighting nav elements when you are on the "current" page of a dynamic site, where the same header file is loaded for every page.
// get the page url of current page
var currentPage = location.href;
//alert("current page is " + currentPage);
// compare page url with nav links. Add css class 'current' to current page and remove from others
$("ul#topnav li a").each(function() {
//console.log(this.href);
if ( currentPage.indexOf( this.href ) > -1 ) { // if this link url is found in the page url then...
$('li.current').removeClass('current'); // find the list item with class of 'current' and remove the class
$(this).parent().addClass('current'); // add 'current' to parent of THIS element
@cobbman
cobbman / wp-config.php
Created February 28, 2013 07:04
Custom settings for WordPress to help with local development and then transferring to a server (this won't always solve all your issues, but it can help with minor sites). keyword: Migrating WordPress
/** custom settings **/
define('WP_SITEURL', 'http://your-site-url/');
define('WP_HOME', 'http://your-site-url/');
define('WP_MEMORY_LIMIT', '64M'); /* Raise memory limit for WooCommerce or other */
@cobbman
cobbman / contact.html
Last active December 14, 2015 07:59
When putting a contact form on a page it's cleaner to have the labels be inside the form elements. This bit of jQuery will remove the values when each element is clicked on and bring it back if the user doesn't enter any information in and leaves the box.
<!--
Notice that the values of each input are what you want it to say when it's not focused,
instead of setting these with JavaScript
(I think it's better this way - keeps the content inside the HTML file).
-->
<form id="contact-form" class="contact" action="javascript:alert('success!');">
<fieldset>
<ul>
<li>
@cobbman
cobbman / header.php
Last active December 14, 2015 07:59
You keep using the same HMTL over and over again to create the same header information on each page, and then one day you realize there must be an easier way. You don't have a CMS set up and it's just a small site with 5-10 HTML pages. Well, put that header into it's own separate 'header.php' file and then on each page in the site, use this to r…
// your header.php file might look something like this (doesn't even have to be betwen <?php ?> statements!
<header>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Store</li>
<li>Contact</li>
@cobbman
cobbman / Display-XML-Block.phtml
Created March 5, 2013 17:54
Magento: Add a layout block into a .phtml file. Display a CMS Block in a phtml file:
<?php echo $this->getChildHtml('block_name_tag'); ?>
<?php
# NOTES:
# replace block_name_tag with the name of the block
# Layout blocks are found under the layout folder. All XML files.
# An example of a block element is:
# <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"></block>
# note that there are differnt types of blocks.
?>
@cobbman
cobbman / detect-browser.php
Last active December 14, 2015 13:19
A PHP script to redirect mobile users to a mobile site. i.e. redirect mobile users from www.yourstore.com to m.yourstore.com
/* detect user agent and load mobile site for mobile devcies only */
# is our user on a mobile device?
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|t
@cobbman
cobbman / mobile exceptions
Created March 6, 2013 00:02
Magento: For loading specific themes based on user-agent, using exceptions in the admin.
In Magento Admin > System > Configuration/Design
Add this exception
iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini