Skip to content

Instantly share code, notes, and snippets.

@WPDevHQ
WPDevHQ / add-theme-support-for-custom-logo.php
Last active April 11, 2016 21:27
How to add Site Logo support to a theme
<?php
/*
* First we need to let WordPress know that our theme supports the output of the "custom-logo"
* We do this by making the "add_theme_support( 'custom-logo' ) plus arrays declaration as follow.
* File: functions.php
*/
function themename_setup() {
add_theme_support( 'custom-logo', array(
'height' => 250,
'width' => 75,
@WPDevHQ
WPDevHQ / woocommerce-discount-amount.php
Last active March 18, 2016 00:32
Display WooCommerce discount in amount i.e. You Save £3.00
<?php
function themeslug_custom_sales_price( $price, $product ) {
$currency = get_woocommerce_currency_symbol();
$percentage = round( $product->regular_price - $product->sale_price, 2 );
return $price . sprintf( __(' <br /><span class="price_save">You Save ' . $currency . '%s', 'woocommerce' ), $percentage . '</span>' );
}
add_filter( 'woocommerce_sale_price_html', 'themeslug_custom_sales_price', 10, 2 ); ?>
@WPDevHQ
WPDevHQ / woocommerce-discount-percentage.php
Last active March 18, 2016 00:32
Display WooCommerce discount as a percentage
<?php
function themeslug_discount_product($price, $product){
global $product;
$discount = $product->sale_price ;
if ($discount) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
$wc_percent = $price .' <span class="product-discount">'. sprintf( __('%s', 'themeslug' ), $percentage . '% OFF</span>' );
}
else{
$wc_percent = $price .' <span class="no_discount">'. sprintf( __('0%s', 'themeslug' ), $percentage . '% OFF</span>' );
@WPDevHQ
WPDevHQ / functions.php
Last active April 11, 2016 21:45
Override WooCommerce "Sale!" text
<?php
/*
* This function assumes you have a customizer setting of the type 'text-field' setup ready for your custom input
* If not then it will return the default that can be changed manually @line 11
*/
function themeslug_woocommerce_sale_flash( $text ) {
if ( get_theme_mod( 'themeslug_onsale_text' ) !='' ) {
$onsale = get_theme_mod( 'themeslug_onsale_text' );
} else {
@WPDevHQ
WPDevHQ / _base.scss
Created March 19, 2016 02:36 — forked from yratof/_base.scss
WooCommerce Checkout for Mobile
@media only screen and (max-width: 760px) {
.woocommerce-cart #content .woocommerce table.shop_table td,
.woocommerce-cart #content .woocommerce-page table.shop_table td,
.woocommerce-checkout #content .woocommerce table.shop_table td,
.woocommerce-checkout #content .woocommerce-page table.shop_table td {
padding: 3px 0;
border-top: 0;
}
@WPDevHQ
WPDevHQ / inline-styles.php
Last active March 23, 2016 20:50
How to add inline styles the right way
<?php
/*
* As a wise theme reviewer advised - theme options are required to be within the Customizer!
*/
function themename_custom_css_adjust() {
$css = '';
$bg_color = get_theme_mod( 'themename_menu_bg_color' );
$link_color = get_theme_mod( 'themename_last_link_color' );
$link_hover = get_theme_mod( 'themename_last_link_hover' );
<?php
add_filter( 'rewrite_rules_array', function( $rules ) {
$new_rules = array(
'shop/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
'shop/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
);
return $new_rules + $rules;
} );
@WPDevHQ
WPDevHQ / woo-custom-redirect
Created August 6, 2016 23:00 — forked from anant1811/woo-custom-redirect
Woocommerce - custom redirection on checkout
//*Add custom redirection
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'http://mysite.com/thank-you-for-your-order/' );
exit;
}
}
@WPDevHQ
WPDevHQ / 0_reuse_code.js
Created August 10, 2016 05:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@WPDevHQ
WPDevHQ / font-awesome.php
Created August 23, 2016 11:27 — forked from justintadlock/font-awesome.php
PHP array of Font Awesome icons.
<?php
// Font Awesome v. 4.6.
function jt_get_font_icons() {
return array(
'fa-glass' => 'f000',
'fa-music' => 'f001',
'fa-search' => 'f002',
'fa-envelope-o' => 'f003',