Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
@aliboy08
aliboy08 / croco-wishlist-compare-customize.js
Created November 22, 2022 09:28
croco wishlist compare - add js cookie save + custom on click events
(function($){$(function(){
function jetCW_customizations(){
var loading = false;
$(document).on('jet-cw-load', function(e, btn, product_id, action){
if( loading ) return;
loading = true;
product_id = product_id.toString();
@aliboy08
aliboy08 / elementor-auto-clear-cache-on-template-save.php
Created November 18, 2022 01:46
elementor auto clear cache on template save
add_action( 'elementor/editor/after_save', function( $post_id, $editor_data ){
if( $post_id == 53 ) {
// footer - auto clear cache - fix for elementor responsive styles reverting on template update
Elementor\Plugin::$instance->files_manager->clear_cache();
}
}, 10, 2 );
@aliboy08
aliboy08 / woo-user-purchased-the-product.php
Created November 17, 2022 04:30
woo - user purchased the product
function ff_user_purchased_product( $user_id, $search_product_id ) {
$args = [
'customer' => $user_id,
'status' => [ 'wc-processing', 'wc-completed' ],
];
$orders = wc_get_orders( $args );
foreach( $orders as $order ) {
foreach( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
if( $product_id == $search_product_id ) return true;
@aliboy08
aliboy08 / woo-product-already-in-cart.php
Created November 17, 2022 04:29
woo - product already in cart
function ff_product_already_added( $product_id ) {
$cart = WC()->cart->get_cart();
if( !count( $cart ) ) return false;
foreach( $cart as $item ) {
if( $product_id == $item['product_id'] ) {
return true;
}
}
return false;
}
@aliboy08
aliboy08 / save-user-details.js
Created November 7, 2022 04:12
gform save user details + elementor popup
(function($){$(function(){
function FF_User_Details(){
this.input_field_keys = [
'field_first_name',
'field_last_name',
'field_email',
'field_phone',
'field_where_build',
@aliboy08
aliboy08 / gsap-typing-v2-with-elementor-on-reveal.js
Last active November 18, 2022 04:07
gsap typing without split text plugin
function custom_typing_animation(){
var els = $('.custom-typing-animation');
if( !els.length ) return;
els.each(function(){
wrap_letters($(this).find('.elementor-heading-title'));
this.typing_observer = new MutationObserver( function(mutationList, observer) {
mutationList.forEach(function(item){
if( item.attributeName !== 'class' ) return;
if( !item.target.classList.contains('animated') ) return;
@aliboy08
aliboy08 / wp-check-load-time.php
Created October 6, 2022 01:00
check load time
add_action( 'after_setup_theme', function(){
$GLOBALS['after_setup_theme_time_start'] = microtime(true);
});
add_action( 'wp_loaded', function(){
$time_end = microtime(true);
pre_debug( 'time start = '. $GLOBALS['after_setup_theme_time_start'] );
pre_debug( 'time end = '. $time_end );
pre_debug( 'wp_loaded = '. ($time_end - $GLOBALS['after_setup_theme_time_start']) );
@aliboy08
aliboy08 / custom-pagination.php
Created October 5, 2022 07:49
Custom Pagination
<?php
$posts_per_page = 12;
$args = [
'post_type' => 'product',
'showposts' => $posts_per_page,
'fields' => 'ids',
'no_found_rows' => true,
];
if( isset($_GET['page']) ) {
@aliboy08
aliboy08 / wp-get-all-parents.php
Created October 2, 2022 01:31
wordpress get parents recursion
function get_term_parent_slug( $term_id, $taxonomy, $parents ) {
$term = get_term_by('id', $term_id, $taxonomy );
$parents[] = $term->slug;
if( $term->parent ) {
// have another parent - recursion
return get_term_parent_slug( $term->parent, $taxonomy, $parents );
} else {
return $parents;
}
}
@aliboy08
aliboy08 / wp-query-search-prioritize.php
Created September 16, 2022 05:58
wordpress search prioritize title then body
function ff_search_use_standard_query_with_priority( $data, $query_args ){
$query_args['no_found_rows'] = true;
$query_args['fields'] = 'ids';
$q = get_posts( $query_args );
if( !$q ) return false;
$s = $query_args['s'];
$data['total_count'] = count( $q );