Skip to content

Instantly share code, notes, and snippets.

View hirejordansmith's full-sized avatar

Jordan Smith hirejordansmith

View GitHub Profile
@hirejordansmith
hirejordansmith / functions.php
Created September 26, 2019 13:57
Add support for ACF custom fields to WooCommerce Attributes
<?php
// Adds a custom rule type.
add_filter( 'acf/location/rule_types', function( $choices ){
$choices[ __("Other",'acf') ]['wc_prod_attr'] = 'WC Product Attribute';
return $choices;
} );
// Adds custom rule values.
add_filter( 'acf/location/rule_values/wc_prod_attr', function( $choices ){
@hirejordansmith
hirejordansmith / functions.php
Last active August 28, 2019 19:54
Move ACF Field Groups back to High (after title) position
<?php
add_action( 'admin_init', 'prefix_reset_metabox_positions' );
function prefix_reset_metabox_positions(){
// for posts
delete_user_meta( wp_get_current_user()->ID, 'meta-box-order_post' );
// for pages
delete_user_meta( wp_get_current_user()->ID, 'meta-box-order_page' );
// for custom post type Sermon Series
@hirejordansmith
hirejordansmith / functions.php
Created June 28, 2019 03:24
How to add a WooCommerce Quick Buy Link without a plugin
<?php
// Outputs the button below the default Add to cart button on Single Product page
add_action('woocommerce_after_add_to_cart_button','hjs_add_quick_buy_link_single', 5);
function hjs_add_quick_buy_link_single() { ?>
<style>
.woocommerce div.product form.cart .button.quick-buy {
background: #f04e3d !important;
border-color: #f04e3d !important;
margin-left: 10px;
}
@hirejordansmith
hirejordansmith / hjs-gform-pre-submission-css-class.php
Created April 4, 2019 19:13
Gravity Forms // gform_pre_submission filter based on field CSS class
<?php
add_action( 'gform_pre_submission', 'pre_submission_handler_one' );
function pre_submission_handler_one( $form ) {
foreach ( $form['fields'] as $field ) {
$cssClass = $field->cssClass;
if ( strpos($cssClass, 'test') !== false) {
$field_id = $field->id;
$date = new DateTime( 'now' );
$_POST["input_$field_id"] = $date->format('U');
}
@hirejordansmith
hirejordansmith / gf-2-3-database-updates.txt
Last active December 12, 2018 13:25
Gravity Forms 2.3 Database Updates
rg_lead_meta -> gf_entry_meta
rg_lead_detail -> gf_entry_meta
rg_lead -> gf_entry
All lead_id columns -> entry_id
rg_form_meta -> gf_form_meta
rg_form_view -> gf_form_view
rg_form -> gf_form
@hirejordansmith
hirejordansmith / facet-wp-infinite-scroll.js
Last active March 13, 2023 18:25 — forked from robneu/facet-wp-infinite-scroll.js
Infinite scroll for FacetWP
/* globals FWP */
/**
* JavaScript for FacetWP Infinite Scroll
*/
( function( $ ) {
'use-strict';
var throttleTimer = null;
var throttleDelay = 100;
@hirejordansmith
hirejordansmith / functions.php
Created February 20, 2018 16:26
Add New Tab to the WooCommerce My Account Page
/**
* @snippet Add New Tab to WooCommerce My Account Page
* @author Hire Jordan Smith // https://hirejordansmith.com
*/
// Register new endpoint to use for My Account page
add_action( 'init', 'hjs_add_account_update_endpoint' );
function hjs_add_account_update_endpoint() {
add_rewrite_endpoint( 'account-update', EP_ROOT | EP_PAGES );
}
@hirejordansmith
hirejordansmith / functions.php
Created February 19, 2018 20:33
HJS // Force WordPress Images to link to Media File instead of Attachment Page Globally
<?php
add_shortcode( 'gallery', 'my_gallery_shortcode' );
function my_gallery_shortcode( $atts ) {
$atts['link'] = 'file';
return gallery_shortcode( $atts );
}
@hirejordansmith
hirejordansmith / base-code.js
Last active April 27, 2020 12:19
How to automatically reload a Gravity Form in a modal
// This would be added to a callback or event function
// Replace "82" with the ID of your form
var gwrf = window.gwrf_82;
if( typeof gwrf != 'undefined' ) {
gwrf.reloadForm();
}
@hirejordansmith
hirejordansmith / pre-populate-gf-dropdown-with-affiliates.php
Last active June 14, 2024 21:25
Pre-populate a Gravity Forms Dropdown field with AffiliateWP Affiliates
<?php
// Add filters for Form ID 8
add_filter( 'gform_pre_render_8', 'populate_posts' );
add_filter( 'gform_pre_validation_8', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_8', 'populate_posts' );
add_filter( 'gform_admin_pre_render_8', 'populate_posts' );
function populate_posts( $form ) {
// Loop through each field searching for any "select" field with the class "populate-affs"