Skip to content

Instantly share code, notes, and snippets.

View monecchi's full-sized avatar

Adriano Monecchi monecchi

View GitHub Profile
@monecchi
monecchi / woocommerce_emails_attach_downloadables.php
Created April 19, 2016 07:50 — forked from garretthyder/woocommerce_emails_attach_downloadables.php
Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments
<?php
// Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments
function woocommerce_emails_attach_downloadables($attachments, $status, $order) {
if ( ! is_object( $order ) || ! isset( $status ) ) {
return $attachments;
}
if ( empty( $order ) ) {
return $attachments;
@monecchi
monecchi / gist:6391d0e011f33e1087b4eeda60344238
Created April 19, 2016 10:48 — forked from thegdshop/gist:3171026
WooCommerce - Add checkbox field to the checkout
<?php
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
@monecchi
monecchi / wiredep.js
Created April 21, 2016 09:44 — forked from tjFogarty/wiredep.js
Gulp + Wiredep + Timber + Twig
var gulp = require('gulp');
var config = require('../config');
var wiredep = require('wiredep').stream;
gulp.task('wiredep', function () {
gulp.src(config.wiredep_file)
.pipe(wiredep({
directory: 'assets/lib',
ignorePath: '..',
fileTypes: {
/*
* TWITTER SHARE BUTTON WITH Bit.ly SHORT LINK SUPPORT
* First, you need to create a function to tell WordPress to get a short URL for your post.
* To do this, you will need a bit.ly account. Once you’ve created an account, go to your Account Settings
* and take note of your API key and your username.
* Now open your functions.php file, scroll all the way to the end and paste in the following code,
* substituting in your username and API key for yourbitlyusername and yourbitlyAPIkey:
*/
<?php
@monecchi
monecchi / nginx.conf
Created May 8, 2016 21:07 — forked from dennisblume/nginx.conf
Yoast NGINX Sitemap Rewrite
# Rewrites for Yoast SEO XML Sitemap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
@monecchi
monecchi / functions-yoast.php
Created May 8, 2016 21:07 — forked from davidperezgar/functions-yoast.php
Disable Yoast SEO Meta
add_action('add_meta_boxes', 'yoast_is_toast', 99);
function yoast_is_toast(){
//capability of 'manage_plugins' equals admin, therefore if NOT administrator
//hide the meta box from all other roles on the following 'post_type'
//such as post, page, custom_post_type, etc
if (!current_user_can('activate_plugins')) {
remove_meta_box('wpseo_meta', 'post_type', 'normal');
}
}
@monecchi
monecchi / variation_table
Created May 19, 2016 14:03 — forked from rsangeethk/variation_table
Woocommerce Display all Variations as table
//Display variation dropdown as table
function woocommerce_variable_add_to_cart() {
global $product, $post;
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<?php
@monecchi
monecchi / woocommerce_product_variables.php
Last active May 19, 2016 14:06 — forked from iampearce/woocommerce_product_variables.php
Get WooCommerce Product Variables in $post Form
<?php
// lets talk variations here
$available_variations = $product->get_available_variations();
foreach($available_variations as $prod_variation) {
$post_id = $prod_variation['variation_id'];
$post_object = get_post($post_id);
// do what you like with the post object here
// you can add the variation to the product cart by linking to ?add-to-cart={variation_id}&quantity=xxx
echo $post_object->post_title;
}
@monecchi
monecchi / woocommmerce-product-variations.php
Created May 19, 2016 14:13 — forked from RadGH/woocommmerce-product-variations.php
For the WooCommerce plugin for WordPress, this function returns all variations of a product by referencing the product ID.
<?php /*
Takes a product ID and returns an array that includes all types of variations of the product, and the attributes of that variation.
Variations are normally returned as a term object. They belong to the original product ID and the taxonomy name is equal to the attribute name.
If a custom variation is provided instead of a term object, the variation will simply be a string of the option's name.
Example return result is given below. This is a single product with one attribute and two different variations.
Array (
[pa_oregon-training-classes] => Array (
[attribute] => Array (
@monecchi
monecchi / functions.php
Created May 22, 2016 07:25 — forked from jchristopher/functions.php
Automatically link to WooCommerce Product Variation detail when searching for a Product Variation SKU
<?php
function my_maybe_woocommerce_variation_permalink( $permalink ) {
if ( ! is_search() ) {
return $permalink;
}
// check to see if the search was for a product variation SKU
$sku = get_search_query();
$args = array(