Skip to content

Instantly share code, notes, and snippets.

View gerrgg's full-sized avatar
💯

Greg Bastianelli gerrgg

💯
View GitHub Profile
@gerrgg
gerrgg / wp_remove_vs_from_content.sh
Last active September 26, 2019 21:50
How to remove Visual Composer Shortcodes from Wordpress content. Bash script which strips WP Bakery shortcodes from wordpress content.
# Greg Bastianelli
# 26-09-1994
# Requires WP-CLI
# Regex's from https://gist.github.com/gemmadlou/7a0189bfae6c2c7268de12f1de822b8a
# Uses an array of regex specifically designed to trim off all wp-bakery visual-studio from your wordpress content.
declare -a arr=("\[/vc(.*?)\]" "\[vc(.*?)\]" "\[custom_font(.*?)\]" "\[/custom_font(.*?)\]" "\[/vc_column_text(.*?)\]" "\[vc_separator(.*?)\]" "\[/vc_column(.*?)\]" "\[vc_row(.*?)\]" "\[portfolio_list(.*?)\]");
for i in "${arr[@]}"
do
@gerrgg
gerrgg / sync_portwest
Last active October 1, 2019 11:20
Downloads the portwest stock on hand CSV, compares items matching on sku and updates accordingly.
#!/bin/bash
# Gregory Bastianelli
# http://gerrg.com/resume
# 30-09-2019
# Could pass a number of flags to quickly loop through and update any field (db column)
# download file
FILENAME='./sohUS.csv'
curl -o "${FILENAME}" http://www.portwest.us/downloads/sohUS.csv
@gerrgg
gerrgg / get_card_type.php
Last active May 21, 2020 13:46
Uses the binlist.net API to return a card's type. Edit the return for even boarder details
<?php
function msp_get_card_type( $card_num ){
/**
* Returns card type based on card number using public BIN API
* @param string $card_number
* @return string $card_type
*/
$ch = curl_init();
@gerrgg
gerrgg / wpo_wcpdf_add_meta_data_to_invoice.php
Last active May 21, 2020 13:45
How to include custom meta data and custom fields to Woocommerce-pdf-invoices-packing-slips plugin.
<?php
// hooks into invoice.php
add_action( 'wpo_wcpdf_after_order_data', 'msp_add_meta_data_to_wpo_invoice', 100, 2 );
function msp_add_meta_data_to_wpo_invoice( $type, $order ){
/**
* Adds custom meta data to WPO generated invoice plugin
* DOC: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/pdf-template-action-hooks/
* @param string $template_type
@gerrgg
gerrgg / woocommerce-sorted-category-descriptions.php
Last active May 21, 2020 16:03
Gets a product's category, sort terms by category hierarchy and add term description to product content.
<?php
function msp_maybe_category_description( $content ){
/**
* Gets current product category, sorts terms in hierarchy order
*
* @param string $content
* @return string $content
*/
@gerrgg
gerrgg / rsync
Created June 1, 2020 14:37
How to copy uploads from remote server to local directory for wordpress.
rsync -v -a -e 'ssh -p 2200' [email protected]:home/wp-content/uploads/ uploads/
// Keep in mind that rsync works left to right (from => target).
// -v verbose lets you know things are happening
// -a archive maintains preserves directory structure
// -e executes a piece of code ( I use it to target a specific port for ssh ).
@gerrgg
gerrgg / woocommerce-get-brand-name.php
Created June 12, 2020 12:48
How to get a product attribute by name using WC_Product->get_attribute( 'brand' ) and link to attribute archive.
<?php
// Put the product's brand and link to archive above product title on single_product page.
add_action( 'woocommerce_single_product_summary', 'msp_brand_name', 1 );
// Put same link on shop page
add_action( 'woocommerce_before_shop_loop_item_title', 'msp_brand_name', 15 );
function msp_brand_name(){
/**
* Get the product's brand name and link to brand archive
<?php
// use woocommerce select2
wp_enqueue_style('select2', WC()->plugin_url() . '/assets/css/select2.css' );
wp_enqueue_script('select2', WC()->plugin_url() . '/assets/js/select2/select2.min.js', array('jquery') );
<?php
function wcfbt_get_variation_dropdown( $product_id ){
/**
* Create a inline dropdown for selecting available product variations
*/
$product = wc_get_product( $product_id );
// if product exists and has available variations to list.
<IfModule mod_setenvif.c>
# Vary: Accept for all the requests to jpeg and png
SetEnvIf Request_URI "\.(jpe?g|png)$" REQUEST_image
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Check if browser supports WebP images
RewriteCond %{HTTP_ACCEPT} image/webp