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 / wp-job-manager-custom-dropdown-field.php
Created February 11, 2020 17:37
WP Job Manager | Add custom dropdown field to admin, frontend listing, list of jobs, and search
<?php
add_filter( 'job_manager_job_listing_data_fields', 'admin_add_hours_field' );
function admin_add_hours_field( $fields ) {
$fields['_job_hours'] = array(
'label' => __( 'Job Hours', 'job_manager' ),
'type' => 'select',
'options' => array('Select hours', '0 - 5' => '0 - 5', '5 - 10' => '5 - 10', '10 - 15' => '10 - 15', '20 +' => '20 +', 'flexible hours' => 'flexible hours'),
'placeholder' => '',
'description' => ''
);
/**
* add a WISIHLIST LINK in the WooCommerce MY ACOUNT sidebar tab area
**/
add_filter ( 'woocommerce_account_menu_items', 'woo_my_wishlist' );
function woo_my_wishlist( $menu_links ){
// we will hook "my_wishlist" later
$new = array( 'my_wishlist' => 'My Wishlist' );
// array_slice() is good when you want to add an element between the other ones
@Garconis
Garconis / woocommerce-checkout-datepicker-adjustments.php
Last active January 6, 2020 20:29
WooCommerce | Checkout Field Editor | Adjust datepicker to have custom date format, certain future range, and blocked dates
<?php
function fs_custom_adjust_datepicker_range () {
// only adjust on Checkout page
if ( is_checkout() ) {
wp_enqueue_script( 'jquery' );
?>
<!-- Checkout datepicker tweaks -->
<script type="text/javascript">
jQuery( document ).ready( function ( e ) {
@Garconis
Garconis / magnific-popup-youtube.js
Created November 8, 2019 21:57
Magnific Popup | Find YouTube anchor link and open it in popup, while also adding additional parameters such as a Playlist ID. Note, this requires magnificPopup JS to be loaded on the page.
jQuery(window).load(function(){
// target YouTube anchor links within this ID
jQuery('#fs-video-playlist a[href*="youtube.com/watch"]').magnificPopup({
type: 'iframe',
iframe: {
markup: '<div class="mfp-iframe-scaler">'+
'<div class="mfp-close"></div>'+
'<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
'</div>', // HTML markup of popup, `mfp-close` will be replaced by the close button
@Garconis
Garconis / woocommerce-adjust-shipping-title-based-on-shipping-class-in-cart.php
Created November 4, 2019 21:37
WooCommerce | Adjust the title of the Shipping Method based if a Shipping Class product is in the Cart
<?php
add_filter('woocommerce_package_rates', 'change_shipping_method_name_based_on_shipping_class', 50, 2);
function change_shipping_method_name_based_on_shipping_class($rates, $package){
// HERE set the shipping class for "Pickup"
$shipping_class_id = 125;
$pickup = false;
$deliver = false;
// Check for the "Pickup" shipping class in cart items
@Garconis
Garconis / .htaccess
Created August 24, 2019 05:33
Cloudways | .htaccess rewrite URL to HTTPS with WWW
# Cloudways force HTTPS with WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
@Garconis
Garconis / force-woocommerce-orders-to-automatically-complete.php
Created August 8, 2019 14:45
WooCommerce | Force orders to auto complete
<?php
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
@Garconis
Garconis / home-woocommerce-pages-anonymous-redirect.php
Created August 8, 2019 14:44
WooCommerce | Hide WooCommerce products and pages for logged-out users and redirect to homepage
<?php
// redirecting woocommerce pages to homepage for logged out users
add_action( 'template_redirect', 'fs_wc_redirect' );
function fs_wc_redirect() {
if ( ! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) {
wp_redirect( home_url() );
exit;
}
}
@Garconis
Garconis / pressable-batcache-append-to-wp-config.php
Created August 6, 2019 16:46
Pressable | Add custom batcache settings to end of wp-config.php file
<?php
$n = '
/** Custom Batcache settings for the end of wp-config.php **/
global $batcache;
if ($batcache && WP_CACHE) {
$batcache->max_age = 86400; // Seconds the cached render of a page will be stored
$batcache->seconds = 3600; // The amount of time at least 2 people are required to visit your page for a cached render to be stored.
}
';
@Garconis
Garconis / functions.php
Created August 5, 2019 13:48
How to display the Shipping Class of each item in the WooCommerce shopping cart
<?php
/**
* Add the shipping class to the bottom of each item in the cart
*/
add_filter( 'woocommerce_cart_item_name', 'shipping_class_in_item_name', 20, 3);
function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
// If the page is NOT the Shopping Cart or the Checkout, then return the product title (otherwise continue...)
if( ! ( is_cart() || is_checkout() ) ) {
return $item_name;