Skip to content

Instantly share code, notes, and snippets.

View tradesouthwest's full-sized avatar
Working remotely

Larry tradesouthwest

Working remotely
View GitHub Profile
<?php // push delivery date forward if it is a friday, saturday or sunday.
<section id="sect-1" class="block" style="display:table;">
<article id="artc-2" style="width:48%;min-height:230px;display:block;float:right;background:#f1f7f5">
<h4>Results</h4>
<div><?php print( display_results() ); ?></div>
<?php function display_results()
{
/**
* procedural
@tradesouthwest
tradesouthwest / woocommerce-sql-removeproduct-data.sql
Created March 13, 2020 21:20
woocommerce sql to remove all product data
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@tradesouthwest
tradesouthwest / woocommerce-category-limit.php
Last active September 20, 2021 05:28
allow only one category in woocommerce cart plus hide price in a cat
// only allow one category to be purchased at a time
add_filter( 'woocommerce_add_to_cart_validation', 'dietweek_only_one_product_category_allowed', 20, 3 );
function dietweek_only_one_product_category_allowed( $passed, $product_id, $quantity) {
// Getting the product categories term slugs in an array for the current product
$term_slugs = wp_get_post_terms( $product_id, 'product_cat', array('fields' => 'slugs') );
// Loop through cart items
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item ){
@tradesouthwest
tradesouthwest / htaccess-for-wp-with-SSL-directives
Created May 9, 2020 00:40
secure wordpress ssl url directive for SSL confidence
# Begin GzipofBreezeWPCache
SetEnv BREEZE_GZIP_ON 1
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
@tradesouthwest
tradesouthwest / script-tags-and-defer-tests.php
Last active June 18, 2020 16:42
wp get registered script tags and display at top of website page
<?php
/*
* Getting registered script tags and display at top of website page for dev only.
* Thanks http://wordpress.stackexchange.com/questions/54064/how-do-i-get-the-handle-for-all-enqueued-scripts
*/
add_action( 'wp_print_scripts', 'wsds_detect_enqueued_scripts' );
function wsds_detect_enqueued_scripts() {
global $wp_scripts;
foreach( $wp_scripts->queue as $handle ) :
echo $handle . ' | ';
@tradesouthwest
tradesouthwest / tsw-defer-reg.php
Created June 18, 2020 17:52
Defer loading of external javascripts, like google ads [wordpress]
<?php
/**
* Defer loading javascript for unregistered scripts (ads)
* @uses $tag(string) The <script> tag for the enqueued script.
* @uses $handle(string) The script's registered handle.
* @uses $src(string) The script's source URL.
* @see https://developer.wordpress.org/reference/hooks/script_loader_tag/
*/
/*function to add async and defer attributes*/
function colormag_child_add_defer_jstags( $tag, $handle ){
@tradesouthwest
tradesouthwest / woo-category-catalog-check.php
Last active June 24, 2020 22:53
Only display YITH Request A Quote button on Woo pages. Parent child relations. Woocommerce
<?php
/**
* Only display YITH Request A Quote button on Woo pages.
* @uses Shortcode from YITH
* Maybe translate manually. && $post->post_parent > 0
* @see https://developer.wordpress.org/reference/functions/is_page/
*/
function betheme_child_request_aquote_echo( )
{
if ( is_home() || is_front_page() || is_page( array(
@tradesouthwest
tradesouthwest / yith-request-quote-view-attributes.php
Last active June 30, 2020 01:51
yith request a quote view to get attribute values into quote table aka woocomerce cart
<?php
/**
* Get product attributes to display on yith-quote table
* @param string $attribute_name Taxonomy name
* @param string $product_id Global value
* @return array Attribute value
*/
function betheme_child_get_product_terms_carton( $attribute_name, $product_id )
{
@tradesouthwest
tradesouthwest / ada-woocommerce-store-notice.php
Last active September 20, 2021 05:28
Script to add ADA compliant links WordPress Woocommerce + change Checkout message text
/**
* Script to add ADA compliant links
* .woocommerce-store-notice__dismiss-link andd all buttons, some with icons class
* @uses wp_footer()
*/
function ibsen_child_hook_javascript_footer()
{
?>
<script id="isben-add-ntccnt" type="text/javascript">
@tradesouthwest
tradesouthwest / wp-session-display-cookies.php
Created August 21, 2020 17:41
Get all raw session meta from all wordpress users.
<?php
/**
* Get all raw session meta from all users
*
* @return array
*/
function readlimit_get_all_sessions_raw() {
global $wpdb;
$results = array();