Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
@aliboy08
aliboy08 / wp-get-terms-by-post-type
Last active October 19, 2018 13:33
WP Get terms by post type
function ff_get_terms_by_post_type( $taxonomies, $args=array() ){
$args = wp_parse_args($args);
if( !empty($args['post_types']) ){
$args['post_types'] = (array) $args['post_types'];
add_filter( 'terms_clauses', 'ff_get_terms_by_post_type_filter',10,3);
}
return get_terms($taxonomies, $args);
}
function ff_get_terms_by_post_type_filter($pieces, $tax, $args) {
global $wpdb;
@aliboy08
aliboy08 / wp-query-check-more-posts.php
Created October 24, 2018 02:00
Check if WP Query have more posts - useful for ajax
@aliboy08
aliboy08 / jquery-ff-equal-heights,js
Created October 24, 2018 02:34
JQuery plugin for setting elements to have equal heights
/*! FF Equal Heights Plugin */
$.fn.ff_equal_heights = function( options ) {
if( !$(this).length ) return;
var $this = this;
var settings = $.extend({
enable_on_resize: true,
disable_on_width: false,
@aliboy08
aliboy08 / ff-swap-children.js
Created October 31, 2018 06:11
Swap child elements jQuery Plugin
/*! FF Swap Children Plugin */
$.fn.ff_swap_children = function( options ) {
if( !$(this).length ) return;
var $this = this;
var settings = $.extend({
window_width: 768
}, options );
@aliboy08
aliboy08 / ff-get-user-location.php
Last active November 2, 2018 12:35
Get user location based on ip
<?php
function ff_get_user_location(){
// Get user ip
if( isset($_SERVER['HTTP_CF_CONNECTING_IP']) ) {
$user_ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else {
if( isset($_SERVER['REMOTE_ADDR']) ) {
$user_ip = $_SERVER['REMOTE_ADDR'];
}
}
@aliboy08
aliboy08 / curved-bottom-only-css.html
Created November 11, 2018 06:15
Curved bottom mask (css-only)
<style>
div {
overflow: hidden;
position: relative;
}
div:before {
content: "";
position: absolute;
bottom: -100px;
left: 50%;
@aliboy08
aliboy08 / retina-script-fix-after-genesis-update.php
Created November 15, 2018 06:38
Retina script fix after genesis update
// Logo Markup
add_filter('genesis_seo_title', 'ff_seo_title', 10, 3);
function ff_seo_title($title, $inside, $wrap) {
// Get Logo
$site_logo = get_field('site_logo', 'option');
$default_logo_url = get_stylesheet_directory_uri() . '/images/logo.png';
$size_attributes = ' width="'. $site_logo['width'] .'" height="'. $site_logo['height'] .'"';
// Set Logo
$logo_url = ( $site_logo ) ? $site_logo['url'] : $default_logo_url;
return buffer_action('fbf_before_site_logo') . apply_filters('fbf_site_logo', '<a href="'. home_url() .'" title="'. get_bloginfo('title') .'"><img id="site_logo_image" '. $size_attributes .' src="'. $logo_url .'" alt="'. get_bloginfo('title') .' Logo" data-rjs="2"/></a>') . buffer_action('fbf_after_site_logo');
@aliboy08
aliboy08 / woo-modify-product-price.php
Created November 16, 2018 12:10
Woocoommerce modify product price
// Add to cart markup - added custom input field for event_id
$price = get_post_meta(get_the_ID(), 'price', true );
if( $price ) {
echo '<form class="cart" action="" method="post" enctype="multipart/form-data">
<div class="quantity">
<label class="screen-reader-text" for="quantity_5beeab967f651">Quantity</label>
<input type="number" id="quantity_5beeab967f651" class="input-text qty text" step="1" min="1" max="" name="quantity" value="1" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric" aria-labelledby="">
</div>
<input type="hidden" name="event_id" value="'. get_the_ID() .'">
<button type="submit" name="add-to-cart" value="119" class="single_add_to_cart_button button alt">Add to cart</button>
@aliboy08
aliboy08 / change-shipping-rate-cost-sample.php
Created November 16, 2018 12:44
Modify shipping rate cost sample
add_filter('woocommerce_package_rates','ff_override_shipping_rate',100,2);
function ff_override_shipping_rate($rates, $package) {
// Get total products quantity on the cart
$total_product_quantity = 0;
foreach( $package['contents'] as $cart_line ) {
$total_product_quantity += $cart_line['quantity'];
}
// If quantity is more than 5, set cost to 10
if( $total_product_quantity > 5 ) {
foreach ($rates as $rate) {
@aliboy08
aliboy08 / js-remove-event-listener.js
Created November 20, 2018 06:15
JS remove event listener
var i = 0;
var load_more_scroll_listener;
function begin_scroll_checker(data) {
load_more_scroll_listener = scroll_check(data);
window.addEventListener('scroll', load_more_scroll_listener);
}
begin_scroll_checker();
function scroll_check(data) {
return function scroll_event(event) {
i++;