Skip to content

Instantly share code, notes, and snippets.

View rayflores's full-sized avatar

Ray Flores rayflores

View GitHub Profile
<?php
add_filter('wc_avatax_order_origin_address', 'verde_change_avatax_order_origin_address', 10, 2 );
// add_filter('wc_avatax_order_destination_address', 'verde_change_avatax_order_origin_address', 10, 2 );
function verde_change_avatax_order_origin_address( $origin_address, $order ){
$origin_address = array(); // empty saved address
$branch_id = get_post_meta($order->id, '_avatax_branch_id', true);
$branch_address = get_post_meta( $branch_id, 'wpsl_address', true );
$branch_city = get_post_meta( $branch_id, 'wpsl_city', true );
@rayflores
rayflores / gist:e8f9cfb92f2509c7164e635b3ec0b4ce
Created March 26, 2019 21:19 — forked from bradyvercher/gist:1576900
WordPress: Sort an array of post objects by any property, remove duplicates, and use post ids as the key in the returned array.
<?php
function sort_posts( $posts, $orderby, $order = 'ASC', $unique = true ) {
if ( ! is_array( $posts ) ) {
return false;
}
usort( $posts, array( new Sort_Posts( $orderby, $order ), 'sort' ) );
// use post ids as the array keys
if ( $unique && count( $posts ) ) {
@rayflores
rayflores / custom-page-template.php
Created February 19, 2019 17:39
html for custom sorted - indexed - list of postmeta that was a serialized json object to start.
<?php
/*
* Template Name: Custom List Page
*/
get_header();
$post_id = get_the_ID();
$meta_list = Sort_The_List::get_postmeta_from_db( $post_id );
if ( empty( $meta_list ) ) {
return;
}
@rayflores
rayflores / sort_by_order.php
Last active February 19, 2019 17:38
sort postmeta that is a serialized object by custom order of your choice - uksort function - custom index list order - always first
<?php
class Sort_The_List {
static public function get_postmeta_from_db( int $post_id ){
$full_meta = [];
$the_meta = get_post_meta( $post_id, '_your_meta_key', true );
foreach( $the_meta as $key => $value ){
if( is_array( $value ) || is_object( $value ) ) {
foreach( $value as $k => $v ) {
@rayflores
rayflores / custom_sort.php
Created December 19, 2018 17:07
custom sorting function 238-355
<?php
namespace Tribe\Project\Theme;
use Tribe\Libs\Post_Type\Post_Object;
use Tribe\Project\Cordoba_Api\Metaboxes;
use Tribe\Project\Post_Meta\Instrument_Meta;
use Tribe\Project\Post_Types\Guitar\Guitar;
use Tribe\Project\Post_Types\Ukulele\Ukulele;
use Tribe\Project\Taxonomies\Family\Family;
use Tribe\Project\Taxonomies\Has_Electronics\Has_Electronics;
@rayflores
rayflores / functions.php
Created December 3, 2018 05:35
Divi shop module - remove products without product images
<?php
# from Divi shop module Shop.php
# $toggle_filter( 'woocommerce_shortcode_products_query', array( $this, 'shortcode_products_query_cb' ), 10 );
# from WC class-wc-shortcode-products.php
# $query_args = apply_filters( 'woocommerce_shortcode_products_query', $query_args, $this->attributes, $this->type );
# $query_args['meta_query'] = WC()->query->get_meta_query();
add_filter( 'woocommerce_shortcode_products_query', 'remove_if_no_thumbnail', 20, 3);
function remove_if_no_thumbnail( $query_args, $attributes, $type ){
@rayflores
rayflores / us-state-names-abbrevs.php
Created May 31, 2018 16:55 — forked from maxrice/us-state-names-abbrevs.php
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@rayflores
rayflores / wc-order-not-clickable.php
Created March 6, 2018 04:29
WooCommerce Make Orders Table Rows Not Clickable
<?php
/* Plugin Name: WooCommerce Orders Table Rows Not Clickable
* Plugin URI: https://rayflores.com
* Description: Orders table rows are no longer clickable on <td> element
* Version: 1.0
* Author: Ray Flores
* Author URI: https://rayflores.com
*/
/**
@rayflores
rayflores / wp_delete_cookies.php
Created January 6, 2018 07:50
Delete and Expire Cookies - Before and After Plugin mod
<?php
/*
Plugin Name: Delete Cookies
Plugin URI: https://rayflores.com/plugins/wp-delete-cookies/
Description: Delete those unwanted cookies from sticking to the computer of the users for so long!
Version: 1.0
Author: Ray Flores
Author URI: https://www.rayflores.com/
*/
@rayflores
rayflores / modal_in_header.js
Created December 28, 2017 23:31
place beaver builder modal in header...
jQuery(document).ready(function()
// when the builder isn’t active…
if ( typeof FLBuilder == 'undefined' && typeof FLBuilderLayout != 'undefined' ) {
// grab main node and replace here, then grab inner header div and replace here
jQuery('.fl-node-5a4543bc2c784').insertAfter('.hero-inner');
}
//And here if you need it to run when the builder is active…
if ( typeof FLBuilder != 'undefined' ) {
// Your JS here.
}