Skip to content

Instantly share code, notes, and snippets.

@ajmorris
ajmorris / sample.php
Last active February 6, 2024 14:43
<?php
// Trying to create a function to use wp_remote_post() instead of cURL.
// Based off this example, http://developers.hubspot.com/docs/methods/forms/submit_form
public function send_hubspot_data( $first_name, $last_name, $email ) {
$hubspotutk = $_COOKIE['hubspotutk']; // grab the cookie from the visitors browser.
$ipaddress = $_SERVER['REMOTE_ADDR']; // IP address.
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $ipaddress,
'pageUrl' => $_SERVER['request_uri'],
@ajmorris
ajmorris / main.yml
Created October 20, 2021 21:03
Simple workflow file for Github Actions to deploy your WordPress theme
# This is a basic workflow to help you get started with Actions
# The name of the script you are intending to run.
name: Deployment
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch.
# I left my branch name as main, but you could change this to whatever your branches are called.
push:
@ajmorris
ajmorris / itms-theme-helpers.php
Created June 23, 2020 12:13
MU-Plugin for Theme Showdown 2020 - https://ithemes.com/training
<?php
/**
* Plugin Name: Theme Showdown 2020 Helper Plugin
* Plugin URI: https://www.ithemes.com/training
* Description: Plugin that includes handy helpful code snippets for Theme Showdown 2020
* Author: iThemes / AJ Morris
* Author URI: https://www.ithemes.com/training
* Text Domain: ithemes-training
* Domain Path: /languages
* Version: 1.0.0
<?php
// Adding this to get the form and entry object from Gravity Forms so I can test the connector.
add_action('gform_after_submission', 'print_form_and_entry_object', 10, 2);
function print_form_and_entry_object($entry, $form) {
ob_start();
var_dump($entry);
var_dump($form);
$contents = ob_get_contents();
ob_end_clean();
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:13
Code for WooCommerce to check if products in the cart belong to one of the categories we're looking for.
<?php
/**
* Check if a specific product category is in the cart
*/
function wc_ninja_category_is_in_the_cart() {
// Add your special category slugs here
$categories = array( 'clothing', 'posters' );
// Products currently in the cart
$cart_ids = array();
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:08
Remove checkout field if product IDs exist. WooCommerce / WordPress
<?php
/**
* Conditionally remove a checkout field based on products in the cart
*/
function wc_ninja_remove_checkout_field( $fields ) {
if ( ! wc_ninja_product_is_in_the_cart() ) {
unset( $fields['billing']['billing_company'] );
}
return $fields;
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:06
Check for specific Product IDs in your cart to return true if they are there. WooCommerce/WordPress
<?php
/**
* Check if a specific product ID is in the cart
*/
function wc_ninja_product_is_in_the_cart() {
// Add your special product IDs here
$ids = array( '45', '70', '75' );;
// Products currently in the cart
$cart_ids = array();
@ajmorris
ajmorris / custom-woo-acf-tabs.php
Created April 18, 2018 17:32
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
<?php
function hwid_load_custom_tab( $tab_key, $tab_info ) {
echo apply_filters( 'the_content', $tab_info['tabContent'] );
}
function hwid_add_content_tabs( $tabs ) {
global $post;
$custom_tabs = get_field( 'tabs', $post->ID );
@ajmorris
ajmorris / acf-fields.php
Last active February 7, 2020 23:47 — forked from hereswhatidid/acf-fields.php
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'acf_product_options',
'title' => 'Product Options',
'fields' => array (
array (
'key' => 'acf_product_options_tabbedcontent_label',
'label' => 'Tabbed Content',
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('headway');
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );