Skip to content

Instantly share code, notes, and snippets.

View gene158's full-sized avatar

Gene gene158

View GitHub Profile
@tarecord
tarecord / get_primary_taxonomy_term.php
Last active October 7, 2023 18:16
Returns the primary term for the chosen taxonomy set by Yoast SEO or the first term selected.
<?php
/**
* Returns the primary term for the chosen taxonomy set by Yoast SEO
* or the first term selected.
*
* @link https://www.tannerrecord.com/how-to-get-yoasts-primary-category/
* @param integer $post The post id.
* @param string $taxonomy The taxonomy to query. Defaults to category.
* @return array The term with keys of 'title', 'slug', and 'url'.
*/
@gregogalante
gregogalante / WoocommerceConditionalPaymentMethods.php
Last active August 11, 2020 00:19
Set conditional payments method based on shipping method select by the user.
<?php
// Hide payment gateways based on shipping method
function payment_gateway_disable( $available_gateways ) {
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if( $chosen_shipping == 1479475819 ) {
unset($available_gateways['cod']);
}
@jaredatch
jaredatch / functions.php
Last active October 16, 2023 11:51
WPForms display form entries with a custom shortcode
<?php
/**
* Custom shortcode to display WPForms form entries.
*
* Basic usage: [wpforms_entries_table id="FORMID"].
*
* Possible shortcode attributes:
* id (required) Form ID of which to show entries.
* user User ID, or "current" to default to current logged in user.
* fields Comma seperated list of form field IDs.
@n7studios
n7studios / soliloquy-random-image-order.php
Created January 21, 2015 16:44
Soliloquy - Random Image Order
<?php
/**
* Plugin Name: Soliloquy - Random Image Order
* Plugin URI: http://soliloquywp.com
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* Description: Randomizes the order of images in a slideshow. Optionally define a limit of how many slides to output.
*/
@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active January 8, 2024 13:24
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' ) );