Skip to content

Instantly share code, notes, and snippets.

@bogdanpopa90
bogdanpopa90 / functions.php
Created September 18, 2017 09:37
Function that adds target blank to external links in WordPress
function is_external_url( $url ) {
$link_url = parse_url( $url );
$home_url = parse_url( home_url() );
if ( ! empty( $link_url['host'] ) ) {
if ( $link_url['host'] !== $home_url['host'] ) {
return 'target="_blank"';
}
}
}
@bogdanpopa90
bogdanpopa90 / functions.php
Created June 23, 2017 13:22
Reposition WooCommerce breadcrumb, ordering and results count outside the shop main content
function THEME_woocommerce_remove_shop_elements(){
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
}
add_action('woocommerce_before_main_content', 'THEME_woocommerce_remove_shop_elements');
function THEME_woocommerce_reposition_shop_elements(){
woocommerce_breadcrumb();
woocommerce_result_count();
@bogdanpopa90
bogdanpopa90 / functions.php
Created May 11, 2017 12:31
Custom WooCommerce Cart notice
function capri_woocommerce_add_to_cart_message( $input ) {
$cart_redirect = get_option( 'woocommerce_cart_redirect_after_add' );
// Check for Cart page url
if ( function_exists( 'wc_get_page_id' ) ) {
$cart_url = get_permalink( wc_get_page_id( 'cart' ) );
} else {
$cart_url = get_permalink( woocommerce_get_page_id( 'cart' ) );
}
@bogdanpopa90
bogdanpopa90 / functions.php
Created April 18, 2017 13:28
Remove SKU only on WooCommerce product pages
function THEMENAME_remove_product_page_sku( $enabled ) {
if ( ! is_admin() && is_product() ) {
return false;
}
return $enabled;
}
add_filter( 'wc_product_sku_enabled', 'THEMENAME_remove_product_page_sku' );
@bogdanpopa90
bogdanpopa90 / scripts.js
Last active March 31, 2017 09:50
Get window width depending on the browser with JavaScript
if ( getWidth() >= 992 ) {
// do something
}
/* Get window width depending on the browser with JavaScript */
function getWidth() {
if (this.innerWidth) {
return this.innerWidth;
}
@bogdanpopa90
bogdanpopa90 / functions.js
Created March 29, 2017 13:22
Detecting outside clicks of an element using JavaScript
/* Verify clicks outside .target-element */
$('.target-element').outside('click', function() {
// do something
}
/* Function that detect outside clicks */
(function($){
$.fn.outside = function(ename, cb){
return this.each(function(){
var self = this;
@bogdanpopa90
bogdanpopa90 / hooks.php
Created March 13, 2017 15:28
Remove breadcrumb on shop category in WooCommerce
<?php
// Remove breadcrumb on shop category
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0 );
?>
@bogdanpopa90
bogdanpopa90 / hooks.php
Created March 13, 2017 15:06
Remove ordering (sorting) on shop category in WooCommerce
<?php
// Remove ordering on shop category
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
?>
@bogdanpopa90
bogdanpopa90 / style.css
Created March 6, 2017 10:07
Display social icons with CSS based on a href (link) using Font Awesome
/**
* Don't forget to include FontAwesome library, version 4.7
*/
.social-icons li a:before {
font-family: FontAwesome;
}
/* Default link icon - keep this icon first */
.social-icons li a[href*="http"]:before,
.social-icons li a[href*="#"]:before {
@bogdanpopa90
bogdanpopa90 / functions.php
Last active February 21, 2017 16:29
Change order for Upsell & Related products sections on single product in WooCommerce
<?php
/**
* Change order for Upsell & Related products sections on single product
*/
function CUSTOM_change_order_upsell_related() {
if ( is_product() ) {
// Remove Upsell section
remove_action( 'woocommerce_after_single_product_summary','woocommerce_upsell_display', 15 );
// Remove Related products section