Skip to content

Instantly share code, notes, and snippets.

Avatar

Ray Flores rayflores

View GitHub Profile
View avatax.php
<?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 Mar 26, 2019 — 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.
View gist:e8f9cfb92f2509c7164e635b3ec0b4ce
<?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 Feb 19, 2019
html for custom sorted - indexed - list of postmeta that was a serialized json object to start.
View custom-page-template.php
<?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 Feb 19, 2019
sort postmeta that is a serialized object by custom order of your choice - uksort function - custom index list order - always first
View sort_by_order.php
<?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 Dec 19, 2018
custom sorting function 238-355
View custom_sort.php
<?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 Dec 3, 2018
Divi shop module - remove products without product images
View functions.php
<?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 — forked from maxrice/us-state-names-abbrevs.php
US State Names & Abbreviations as PHP Arrays
View us-state-names-abbrevs.php
<?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 Mar 6, 2018
WooCommerce Make Orders Table Rows Not Clickable
View wc-order-not-clickable.php
<?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 Jan 6, 2018
Delete and Expire Cookies - Before and After Plugin mod
View wp_delete_cookies.php
<?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 Dec 28, 2017
place beaver builder modal in header...
View modal_in_header.js
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.
}