Skip to content

Instantly share code, notes, and snippets.

View yratof's full-sized avatar
🍊
Eating an orange

Andrew yratof

🍊
Eating an orange
View GitHub Profile
@yratof
yratof / function.php
Created November 4, 2015 09:11
Add body class to woocommerce category when display mode is set to subcategory
<?php
add_filter( 'body_class', function ( $classes ) {
$term = ( get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') ) );
if ( !$term )
return $classes;
if ( 'subcategories' == get_metadata( 'woocommerce_term', $term->term_id, 'display_type', 1 ) ) {
$classes[] = 'display-subcategories';
}
return $classes;
} );
@yratof
yratof / acf.php
Created October 28, 2015 09:01
Image and Mobile image for Advanced custom fields 5 + wordpress mobile
<?php
$image = get_sub_field('background_image');
// Image related details
$img_title = $image['title'];
$alt = $image['alt'];
$size = 'hero-video';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
@yratof
yratof / functions.php
Created October 27, 2015 09:54
Displat advanced custom fields to Woocommerce Reviews
<?php
add_action( 'woocommerce_review_before_comment_meta', 'comment_title' );
function comment_title(){
$field = get_field('title', 'comment_' . get_comment_ID());
if($field){
echo '<h4>' . $field .'</h4>';
}
}
@yratof
yratof / functions.php
Last active October 23, 2015 07:18
Function for getting the featured image URL
function get_thumbnail_url($size) {
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id, $size, true);
if (has_post_thumbnail()) { echo $image_url[0]; }
};
@yratof
yratof / taxonomy.php
Last active April 29, 2016 23:24
List all taxonomies and loop their posts
<?php
/*
* Loop for taxonomies to show their posts
*/
$taxonomy = 'brand';
$terms = get_terms($taxonomy);
foreach ($terms as $term) {
$wpq = array (
@yratof
yratof / scroll.js
Last active December 16, 2015 12:43
Scroll until hit a class / element
<script type="text/javascript">
jQuery(document).ready(function($){
$.fn.scrollBottom = function() {
return $(document).height() - this.scrollTop() - this.height();
};
$(window).scroll(function () {
// Pick the element you want to move
var offset = $('#parent').offset();
// This is the top of the view
@yratof
yratof / functions.php
Last active July 12, 2019 19:14
woocommerce mini cart
<?php
// Ensure cart contents update when products
// are added to the cart via AJAX
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
echo '<a class="cart-contents" href="' . $woocommerce->cart->get_cart_url() .'" title="' . __( 'View your shopping cart', 'drivdigital' ) .'">';
echo sprintf( _n( '%d item', '%d items', $woocommerce->cart->cart_contents_count, 'drivdigital' ), $woocommerce->cart->cart_contents_count) . ' - ' . $woocommerce->cart->get_cart_total();
echo '</a>';
@yratof
yratof / woo-rating.scss
Created October 6, 2015 08:48
Woocommerce Star Rating SCSS
p.stars {
position: relative;
font-size: u(1.5rem);
margin: 0;
text-align: center;
width: 200px;
margin: 0 auto;
a {
@yratof
yratof / fire-safety-alias.sh
Last active May 11, 2016 11:51
Incase of fire
# Fire Escape // Add this alias incase theres a fire.
alias fire='git branch -b emergency-fire && git add -A && git commit -m "Theres a fire happening, so Im pushing everything I have so far incase the computers dont make it out alive!" && git push'
@yratof
yratof / download.sh
Created September 21, 2015 13:10
Download a website for Static use
wget -r -P / --user-agent="" -e robots=off --wait 1 -E http://website.com