Skip to content

Instantly share code, notes, and snippets.

View Garconis's full-sized avatar
🐞
Debugging

Jon Fuller Garconis

🐞
Debugging
View GitHub Profile
@Garconis
Garconis / .htaccess
Created October 10, 2016 12:23
.htaccess rewrite HTTP to HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@Garconis
Garconis / woocommerce-customer-order-csv-export-tax-status.php
Last active August 30, 2017 22:07
WooCommerce Customer / Order CSV Export | Add a column to show custom text based on if there was sales tax or not
<?php
/**
* Order Export
* Within the Custom Formats > Column Mapping, add your custom column name and set the Data Source to Static, and leave the Value field blank (since we set it here instead anyway)
* This function sees if your order or line item had any tax, and if so, it fills your custom column with "Taxed". Otherwise, the column will say "Not Taxed".
*/
function fs_wc_csv_export_trim_data( $order_data ) {
for( $i = 0; $i < count( $order_data ); $i++ ) {
if ( isset( $order_data[ $i ]['order_line/tax_id/id'] ) ) {
@Garconis
Garconis / woocommerce-customer-order-csv-export-user-custom-field.php
Last active August 30, 2017 22:09
WooCommerce Customer / Order CSV Export | Add a custom meta field from the User (Customer) associated with a WooCommerce Order
<?php
/**
* Order Export
* Within the Custom Formats > Column Mapping, add your custom column name and set the Data Source to Static, and leave the Value field blank (since we set it here instead anyway)
* This function takes that custom field (based on the name you set it to) and then finds the user associated with the order (based on the customer_id of the order), and then displays the user's custom field you specify.
*/
// Tweak content of certain fields in the order export
function fs_wc_csv_export_trim_data( $order_data ) {
for( $i = 0; $i < count( $order_data ); $i++ ) {
@Garconis
Garconis / body-time-date-classes.php
Last active August 30, 2017 22:12
WordPress | Add current time, date, and day to body classes via function
<?php
// Add the times and days to the body classes
// e.g., date-day-wednesday date-ymd-20170614 date-month-june time-military-1317 time-pm time-early-afternoon
add_filter( 'body_class', 'add_date_info_to_class_names' );
function add_date_info_to_class_names( $classes ) {
// current day of week name
$classes[] = 'date-day-' . strtolower(date_i18n('l'));
// current full date YYYYMMDD
$classes[] = 'date-ymd-' . strtolower(date_i18n('Ymd'));
@Garconis
Garconis / woocommerce-email-featured-products.php
Last active August 30, 2017 22:12
WooCommerce | Add Featured Products to bottom of certain WooCommerce emails
@Garconis
Garconis / post-featured-image-based-on-term.php
Last active August 30, 2017 22:14
WordPress | Set a default featured image (post thumbnail) to each post, based on the term (e.g., Tag) that is assigned to the post. Essentially this sets a featured image for the custom terms you specify (of a specified custom taxonomy).
<?php
function default_category_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
$terms = get_the_terms($post->ID, 'jobtype');
$number = sizeof ($terms);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
@Garconis
Garconis / woocommerce-customer-order-csv-export-hacks.php
Last active August 30, 2017 22:15
WooCommerce Customer / Order CSV Export | random hacks
<?php
// Add Custom Column Headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'carrier' => 'Carrier',
'line_number' => 'Line Number',
// add other column headers here in the format column_key => Column Name
);
@Garconis
Garconis / shortcode-to-list-pages-of-taxonomy.php
Last active August 31, 2017 21:08
WordPress | Create a shortcode that lists pages of a custom taxonomy
<?php
/* Usage:
[fs-local-type type="wordpress"]
You can add additional parameters to the shortcode to override settings
Note: "local-type" is the name of the Taxonomy, and "wordpress" is the name of one of the terms
*/
// create shortcode to list all Local Types
add_shortcode( 'fs-local-type', 'fs_local_type_shortcode' );
@Garconis
Garconis / add-taxonomy-to-page.php
Last active September 13, 2017 17:50
WordPress | Add a custom "category-style" taxonomy to Pages
<?php
/**
* Add custom Local taxonomies
* This basically lets you create Categories for Pages (similar to what you can do for Posts)
*
* Additional custom taxonomies can be defined here
* http://codex.wordpress.org/Function_Reference/register_taxonomy
*/
function fs_add_local_page_taxonomies() {
@Garconis
Garconis / default-taxonomy-term-for-cpt.php
Last active September 14, 2017 12:32 — forked from mayeenulislam/Default Taxonomy Term for CPT
WordPress | Make Default taxonomy term(s) for Custom Post Type
<?php
/**
* Add an automatic default custom taxonomy for custom post type.
* If no taxonomy term is selected during post creation, the custom post will be assigned the specififed taxonomy terms during save.
* Just change the 'your-cpt-type' to your custom post type name
* and change 'fruit_tags' and 'soda_flavors' to the taxonomy slug(s) you want to target
* and change 'apple' and 'banana' and 'cola' with the slug(s) of the term(s) you want to make default
* you can add multiple taxonomy at once so the 'soda_flavors' line is applicable only then
*/