Skip to content

Instantly share code, notes, and snippets.

View tharmann's full-sized avatar

Tate Harmann tharmann

View GitHub Profile
@tharmann
tharmann / functions.php
Last active March 8, 2024 17:33
Customize WooCommerce Structured Data to load via JS - for cache prevention
<?php
/* remove default WC structured data and add our custom process which adds an id to the script tag and loads the script content via js to avoid caching*/
function remove_wc_sd_output_footer() {
remove_action( 'wp_footer', array( WC()->structured_data, 'output_structured_data' ), 10 );
add_action( 'wp_footer', 'custom_structured_data_output_cb', 10 );
}
add_action( 'init', 'remove_wc_sd_output_footer' );
function custom_structured_data_output_cb() {
$types = cust_get_data_type_for_page();
import csv
with open('wc-product-export-10-5-2023-1683750652005 - wc-product-export-10-5-2023-1683750652005.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count += 1
else:
col_count = 0
@tharmann
tharmann / functions.php
Created March 2, 2020 20:29 — forked from lukecav/functions.php
Set cart expiration interval to 72 hours in WooCommerce
add_filter('wc_session_expiring', 'filter_ExtendSessionExpiring' );
add_filter('wc_session_expiration' , 'filter_ExtendSessionExpired' );
function filter_ExtendSessionExpiring($seconds) {
return 60 * 60 * 71;
}
function filter_ExtendSessionExpired($seconds) {
return 60 * 60 * 72;
}
@tharmann
tharmann / pack_items.php
Last active August 25, 2021 07:45
4D Packer Idea Using Cloudstek's LAFF Packer - splits items into increasingly smaller chunks until everything fits into boxes (based on dimensions and weight)
<?php
//Uses: https://github.com/Cloudstek/php-laff
//THE doc: 'https://www.parkbeachsystems.com/images/usps/An_Efficient_Algorithm_for_3D_Rectangular_Box_Packing.pdf'
echo '<pre>';//readability
//DATA: array of defined boxes for shipping -outer and inner dimensions plus weight:
$boxes = array(
array( 'ol' => 8.125, 'ow' => 8.125, 'oh' => 4.125, 'il' => 8, 'iw' => 8, 'ih' => 4, 'max_weight' => 20 ),
array( 'ol' => 12.5, 'ow' => 9.875, 'oh' => 3.75, 'il' => 11.25, 'iw' => 9.75, 'ih' => 3.625, 'max_weight' => 10 ),
@tharmann
tharmann / functions.php
Created January 13, 2020 15:25
Customize Divi search module to include WooCommerce products
<?php
/*Add products to divi search module. Source: https://intercom.help/elegantthemes/en/articles/3030197-how-to-enable-products-and-other-post-types-in-divi-s-search-module */
function custom_remove_default_et_pb_custom_search() {
remove_action( 'pre_get_posts', 'et_pb_custom_search' );
add_action( 'pre_get_posts', 'custom_et_pb_custom_search' );
}
add_action( 'wp_loaded', 'custom_remove_default_et_pb_custom_search' );
function custom_et_pb_custom_search( $query = false ) {
if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {
@tharmann
tharmann / functions.php
Created June 10, 2019 20:19
WooCommerce Custom "Return to Shop" link on empty cart
<?php
function wc_empty_cart_redirect_url() {
$url = site_url( '/custom-shop-url/', 'https' );
return $url;
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
@tharmann
tharmann / woocommerce-optimize-scripts.php
Created June 7, 2019 14:21 — forked from DevinWalker/woocommerce-optimize-scripts.php
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
CREATE TABLE `wp_yoast_seo_links` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`post_id` bigint(20) unsigned NOT NULL,
`target_post_id` bigint(20) unsigned NOT NULL,
`type` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `link_direction` (`post_id`,`type`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@tharmann
tharmann / fix-wordpress-permissions.sh
Created May 30, 2019 18:45 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@tharmann
tharmann / extractcss.js
Created January 30, 2019 16:27 — forked from renoirb/extractcss.js
Extract CSS for a given element
/**
* Based on work from krasimirtsonev
*
* http://krasimirtsonev.com/blog/article/csssteal-chrome-extension-that-extracts-css
*/
// helper function for transforming
// node.children to Array
function toArray (obj, ignoreFalsy) {
var arr = [], i;