Skip to content

Instantly share code, notes, and snippets.

View mtruitt's full-sized avatar

Mark Truitt mtruitt

  • Maryland
View GitHub Profile
@mtruitt
mtruitt / guten-disabled.php
Created December 6, 2018 19:20
Disables Gutenberg
<?php
/**
* Plugin Name: Disable Gutenberg
* Description: Uses filters to disable Gutenberg.
* Author: Mark Truitt
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Basic security, prevents file from being loaded directly.
@mtruitt
mtruitt / serialized_metadata.php
Created October 29, 2018 19:09
Pull posts by serialized ACF field
<?php
/* Setup custom query to get posts with ACF field for Author
* First we need to get the ID and pass this for the meta data
* Set the key to the name of the field then compare to like so we pull any that contain it
* Use Sprintf ti run through to check against that
*/
$attorneyID = get_the_id();
$args = array(
'post_type' => 'post',
'meta_query' => array(
@mtruitt
mtruitt / custom_dropdown.php
Last active December 20, 2023 15:47
Remove zipcode field and add custom dropdown in its place.
<?php
// Lets remove the postcode
add_filter( 'woocommerce_checkout_fields' , 'custom_wc_checkout_fields' );
function custom_wc_checkout_fields( $fields ) {
unset( $fields['billing']['billing_postcode']);
$fields['billing']['shipping_code'] = array(
'type' => 'select',
@mtruitt
mtruitt / slack-webhook.php
Created May 7, 2018 20:59
Send via Slack Webhook
<?php
$message = array( 'text' => 'This is a test message via slack and curl' );
$data_message = json_encode( $message );
$ch = curl_init( 'slack webhook goes here' );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_message);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
@mtruitt
mtruitt / product_varations.php
Created April 25, 2018 19:34
Increase WooCommerce Variations per page in the admin
<?php
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'admin_increase_variations_per_page' );
function admin_increase_variations_per_page() {
return 50;
}
@mtruitt
mtruitt / woocommerce-enable-free-shipping-per-product.php
Created April 22, 2018 05:25 — forked from BFTrick/woocommerce-enable-free-shipping-per-product.php
Enable Free Shipping on a per product basis in WooCommerce.
<?php
/**
* Plugin Name: WooCommerce Enable Free Shipping on a Per Product Basis
* Plugin URI: https://gist.github.com/BFTrick/d4a21524a8f7b25ec296
* Description: Enable free shipping for certain products
* Author: Patrick Rauland & eugenf
* Author URI: http://speakinginbytes.com/
* Version: 1.0.2
*
* This program is free software: you can redistribute it and/or modify
@mtruitt
mtruitt / change_price.php
Created January 24, 2018 17:09
Change Price filter - Change texted or price based on conditions
<?php
function change_price($price) {
if ( $price == wc_price( 0 ) )
return 'FREE';
elseif ( $price == '' ) {
return 'Coming Soon';
@mtruitt
mtruitt / user_role_fee.php
Created January 13, 2018 01:40
Apply fee based on user role
<?php
function woo_add_cart_fee() {
global $woocommerce;
$current_user = wp_get_current_user();
if ( in_array( 'residential', $current_user->roles, true) ) {
$woocommerce->cart->add_fee( __( 'Custom', 'woocommerce' ), 5 );
@mtruitt
mtruitt / woocommerce_shipping_package_name.php
Created December 21, 2017 20:30
WooCommerce - Change Shipping Text to Shipping & Handling
<?php
add_filter( 'woocommerce_shipping_package_name' , 'woocommerce_replace_text_shipping_to_delivery', 10, 3);
/**
*
* Function to replace shipping text to shipping & handling text
*
* @param $package_name
* @param $i
* @param $package
@mtruitt
mtruitt / remove_products_from_cart.php
Last active November 16, 2017 22:32
Remove Products based on a specific product getting added.
<?php
function remove_products_from_cart( $cart_item_key ) {
// Products allowed with gift sub
$allowed_products = array( 230973 , 231122, 230510 );
// Gift Subscription Product ID
$gift_product_id = 230973;
// Lets get all the IDs in the cart