Skip to content

Instantly share code, notes, and snippets.

@gzalinski
gzalinski / HubSpot & GravityForms
Created March 16, 2020 11:46
HubSpot CURL for Gravity Form
function curl_to_hubspot($entry, $str_post, $form_ID){
$hubspotutk = $_COOKIE['hubspotutk'];
$portalID = '******'; //HubSpot USER ID
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $entry['ip'],
'pageURL' => $entry['source_url'],
'pageName' => get_the_title( $entry['post_id'])
@gzalinski
gzalinski / acf-rule-terms.php
Last active May 25, 2022 14:35
[ACF rule terms] ACF specific taxonomy term #wp #acf
<?php
add_filter( 'acf/location/rule_types', 'acf_location_rules_types', 999 );
function acf_location_rules_types( $choices ) {
$tax_label = __( 'News Type' ); //<--YOUR LABEL
$key = __('Forms', 'acf');
if ( ! isset( $choices[ $key ] ) ) {
$choices[ $key ] = [];
}
@gzalinski
gzalinski / function.php
Last active May 25, 2022 13:59
[Contact Form 7] connect script and style when gutenberg block is detected #cf7 #wp
/**
* CF7 Optimize Enqueue
*/
add_action( 'wp_enqueue_scripts', 'cf7_optimize_equeues' );
add_action( 'admin_enqueue_scripts', 'cf7_optimize_equeues' );
function cf7_optimize_equeues(){
global $post;
if( !class_exists( 'WPCF7' ) || !$post ) {
return;
@gzalinski
gzalinski / function.php
Created August 27, 2021 15:41
Woocommerce Mini Cart with ajax count update
<?php
/**
* @title: WC Mini Cart
* @usage: echo do_shortcode( '[xcminicart]' );
*/
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}
@gzalinski
gzalinski / function.php
Created September 9, 2021 05:25
WP Upload Image from Front-End
<?php
/**
* Create the image attachment and return the new media upload id.
*
* @param $fileObject
* @return false|int|WP_Error
* @see http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example
* @since 1.0.0
*/
@gzalinski
gzalinski / SQL Run
Created September 13, 2021 13:13
SQL Delete Post Type
//Delete all POSTS META
DELETE
FROM `wp_postmeta`
WHERE post_id in (SELECT id
FROM `wp_posts`
WHERE `post_type` = 'post' )
//Delete all POSTS
DELETE FROM `wp_posts`
WHERE `post_type` = 'post'
@gzalinski
gzalinski / function.php
Created September 13, 2021 14:37
Address to geocode / coordinates
function geocode($address)
{
// url encode the address
$address = urlencode($address);
$apiKey = GMAP_API_KEY;
// google map geocode api url
$url = "https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key={$apiKey}";
// get the json response
$resp_json = file_get_contents($url);
// decode the json
@gzalinski
gzalinski / XC_ProductCategories.php
Created September 14, 2021 18:12
Get product categories with setting and display in list/menu/dropdown
<?php
/**
* Class XC_ProductCategories
* @usage $cat_list = new XC_ProductCategories();
* @usage $cat_list->render($attributes);
*/
class XC_ProductCategories {
public $defaults
@gzalinski
gzalinski / script.js
Last active May 25, 2022 14:35
[jQuery catch ajax complete event] #js #snippet #ajax
$(document).ajaxComplete(function (event, xhr, settings) {
//if (!settings.url.includes('update_listing_account')) { return; }
if (typeof settings.data != 'object') { return }
if (settings.data.get('action') != 'update_listing_account') { return }
if (typeof xhr.responseText != 'undefined') {
const response = $.parseJSON(xhr.responseText)
}
});
@gzalinski
gzalinski / template.php
Created November 17, 2021 09:36
Woocommerce product query on sale between two date
<?php
$query_args = array(
'post_type' => [ 'product_variation', 'product' ],
'posts_per_page' => - 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_sale_price_dates_from',
'value' => time(),