Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Méric smeric

View GitHub Profile
@smeric
smeric / woocommerce-custom-taxonomy-product-item.php
Last active Aug 29, 2015
Register "item" custom taxonomy for woocommerce products
View woocommerce-custom-taxonomy-product-item.php
<?php
/**
* Woocommerce "item" taxonomy
*
* This plugin is a template to add a custom taxonomy to products in woocommerce.
* One should search/replace every "Item" occurence with the taxonomy name.
*
* @link https://gist.github.com/smeric/523c54a16f2ed1870a60
* @since 1.0.0
* @package woocommerce_custom_taxonomy_product_item
@smeric
smeric / woocommerce-custom-extra-tab.php
Last active Jan 21, 2019
Adds a metabox to define a custom tab title and content on woocommerce product pages.
View woocommerce-custom-extra-tab.php
<?php
/**
* Woocommerce custom extra tab
*
* Adds a metabox to define a custom tab label and content on woocommerce product pages. Also remove predifined
* description tab title so we can define our own directly inside tab content.
*
* @link https://gist.github.com/smeric/ff09b2f993dc8378a04a
* @version 1.0.1
* @package woocommerce_custom_extra_tab
@smeric
smeric / gist:0c425adf9e9439e3c076
Last active Aug 29, 2015
Redirect WooCommerce customer to profile page after a successful login through wp-login.php
View gist:0c425adf9e9439e3c076
<?php
/**
* Redirect WooCommerce customer to profile page after a successful login through wp-login.php or
* redirect any unauthorised user trying to access any wp-admin files.
*
* @author Sébastien Méric <sebastien.meric@gmail.com>
* @param string $redirect_to URL to redirect to.
* @return string
*/
add_action( 'init', 'woocommerce_custom_redirect_customer_to_account_page' );
@smeric
smeric / attachment.php
Last active Aug 29, 2015
WordPress plugin used to allow attachment download with one click.
View attachment.php
<?php
/**
* Force attachments download :
*
* In order for this to work, when you insert the file into your post through the media uploader,
* you have to select Post URL rather than File URL in the Link URL field before inserting into your post.
* A link to a filename will follow the browser's preferences, but by linking to the WP post link,
* you can control its behaviour.)
*
* @link https://gist.github.com/smeric/cb4520e848aaa0be703c
@smeric
smeric / remove-old-slugs-redirects.php
Last active May 27, 2020
WordPress plugin. Removes selected old slugs/permalinks from database.
View remove-old-slugs-redirects.php
<?php
/**
* Remove old slugs redirects.
*
* Removes selected old slugs/permalinks from database.
*
* @package WordPress_Remove_Old_Slugs_Redirects
* @author Sébastien Méric <sebastien.meric@gmail.com>
* @credit Algoritmika Ltd. <http://www.algoritmika.com>
* @license GPL-2.0+
View plugin-name include class-plugin-name-loader.php
<?php
/**
* Register all actions, filters and shortcodes for the plugin
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
@smeric
smeric / woocommerce-add-to-cart-before-applying-coupon.php
Last active Jul 23, 2018
Made to be used with the "Smart Coupons" WooCommerce extention. If we apply coupon from url and the coupon is dedicated to a specific product, the coupon is not applied if the product is not already in cart. So, before applying the coupon we add this product to cart.
View woocommerce-add-to-cart-before-applying-coupon.php
<?php
/**
* Add to cart before applying coupon
*
* Made to be used with the "Smart Coupons" WooCommerce extention.
* If we apply coupon from url and the coupon is dedicated to a specific product, the coupon is not applied if
* the product is not already in cart. So, before applying the coupon we add this product to cart.
*
* @link
* @version 1.0.1
@smeric
smeric / Wordpress RSS 2.0 image enclosure .php
Last active Oct 14, 2015 — forked from supermethod/Wordpress RSS 2.0 image enclosure
How to add post image(s) as enclosure(s) to a wordpress RSS feed item - add to functions.php
View Wordpress RSS 2.0 image enclosure .php
<?php
/**
* Add post type images to feed items
*/
add_action('rss2_item', 'add_images_in_feed' );
function add_images_in_feed() {
global $post;
// Thumbnail...
$thumbnail_ID = get_post_thumbnail_id( $post->ID );
@smeric
smeric / add2any_custom_js.php
Last active Oct 30, 2015
WordPress AddToAny custom script to : push shared data to datalayer for GTM, re-shape title to remove special characters & use shortlink for Twitter
View add2any_custom_js.php
<?php
/**
* AddToAny : custom script inserted into the document head
*
* Push shared data to datalayer for GTM
* Re-shape title to remove special characters
* Use shortlink for Twitter
*
* see https://www.addtoany.com/ext/google_analytics/
* see https://www.addtoany.com/buttons/customize/wordpress/events
View smooth-scroll.js
/**
* Smooth scroll :
* <a href="#top" class="go-top">Top</a>
* $( '.go-top' ).click( function( e ){ e.preventDefault(); $( this ).autoscroll( $( this ).attr( 'href' ) ); });
**/
( function( $ ) {
$.fn.autoscroll = function( selector ) {
$( 'html,body' ).animate({
scrollTop: $( selector ).offset().top
}, 200);