Skip to content

Instantly share code, notes, and snippets.

View mglaman's full-sized avatar

Matt Glaman mglaman

View GitHub Profile
@mglaman
mglaman / commerce-free-shipping.json
Last active December 24, 2015 08:49
Drupal rule to provide free shipping on all shipping services using calculation rules.
{ "rules_free_shipping_offer" : {
"LABEL" : "Free Shipping offer",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_shipping" ],
"ON" : [ "commerce_shipping_calculate_rate" ],
"IF" : [
{ "data_is" : { "data" : [ "commerce-line-item:type" ], "value" : "shipping" } },
{ "data_is" : {
"data" : [ "commerce-line-item:order:commerce-order-total:amount" ],
"op" : "\u003E",
@mglaman
mglaman / commerce_sort_shipping.info
Created October 12, 2013 13:35
Sorts Drupal Commerce shipping methods by price
name = Sort Shipping by Price
description = Sorts shipping by price.
package = Commerce (contrib)
dependencies[] = commerce
core = 7.x
@mglaman
mglaman / alter_line_item_label
Created November 9, 2013 20:02
Example rule for altering a line item's label when adding a product to the cart. When a product is added to the cart a line item is created for that order, with its title being the product's SKU. This allows altering of the SKU when added to the order.
{ "rules_alter_line_item_label" : {
"LABEL" : "Alter line item label",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_cart" ],
"ON" : { "commerce_cart_product_add" : [] },
"IF" : [
{ "entity_is_of_type" : { "entity" : [ "commerce-line-item" ], "type" : "commerce_line_item" } },
{ "data_is" : { "data" : [ "commerce-product:type" ], "value" : "product" } }
],
@mglaman
mglaman / free-shipping-us.json
Created November 27, 2013 17:59
Drupal Commerce free shipping rule for contiguous United States - excludes AK, HI, and military bases.
{ "rules_free_shipping_us" : {
"LABEL" : "Free Shipping offer (US)",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"REQUIRES" : [ "commerce_order", "rules", "commerce_line_item", "commerce_shipping" ],
"ON" : [ "commerce_shipping_calculate_rate" ],
"IF" : [
{ "NOT commerce_order_compare_address" : {
"commerce_order" : [ "commerce-line-item:order" ],
"address_field" : "commerce_customer_shipping|commerce_customer_address",
@mglaman
mglaman / drupal-twitter-verify
Created December 4, 2013 16:08
Adds meta tag to verify site with Twitter on Drupall
function mytheme_preprocess_html($vars) {
$twitter_account = array(
'#tag' => 'meta',
'#attributes' => array(
'property' => 'twitter:account_id',
'content' => '8665962',
),
);
drupal_add_html_head($twitter_account, 'twitter:account_id');
}
@mglaman
mglaman / mymodule_view_modes.info
Created January 13, 2014 17:56
Simple Drupal module to add display view modes
name = Custom Entity Display Modes
description = Adds additional display modes
core = 7.x
@mglaman
mglaman / woocommerce-products.sql
Last active August 7, 2023 13:52
MySQL query for wooCommerce to export products.
SELECT product.ID as product_id, product.post_title as product_name, replace(product.post_content, '"', "'") as product_content, product_sku.meta_value as product_sku, product_price.meta_value as product_price, product_weight.meta_value as product_weight
FROM wp_posts as product
LEFT JOIN wp_postmeta as product_sku ON product.ID = product_sku.post_ID
LEFT JOIN wp_postmeta as product_price ON product.ID = product_price.post_ID
LEFT JOIN wp_postmeta as product_weight ON product.ID = product_weight.post_ID
WHERE (product.post_type = 'product' OR product.post_type = 'product_variation') AND product_sku.meta_key = '_sku' AND product_price.meta_key = '_price' AND product_weight.meta_key = '_weight'
ORDER BY product_id ASC
$('.responsive-menu li.menu-parent').hover(
function() {
$(this).find('.sub-menu').addClass('active');
},
function() {
$(this).find('.sub-menu').removeClass('active');
}
);
{
"bold_folder_labels": true,
"caret_style": "wide",
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"default_line_ending": "unix",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"fallback_encoding": "UTF-8",
"find_selected_text": true,
@mglaman
mglaman / menu_get_item_alter-custom-theme.php
Created March 11, 2014 22:09
Allows you to define a theme_callback and change default theme. Useful when using Admin theme for node/edit, but you want forums to use default.
<?php
/**
* Implements hook_menu_get_item_alter().
*/
function mymodule_menu_get_item_alter(&$router_item, $path, $original_map) {
if ($router_item['path'] == 'node/add/forum') {
$router_item['theme_callback'] = 'mymodule_menu_theme_callback';
}
}