Skip to content

Instantly share code, notes, and snippets.

View omniacode's full-sized avatar

Jason Ryan omniacode

View GitHub Profile
@omniacode
omniacode / formidable-forms-ticket-limit.php
Last active December 2, 2022 16:56
Formidable Forms - Limit Amount of Tickets that Can Be Purchased
<?php
add_filter('frm_validate_field_entry', 'max_100_tickets', 10, 3);
function max_100_tickets( $errors, $posted_field, $posted_value ) {
$field_id = 249; // change this to the ID of the Quantity Field
$tickets_requested = $_POST['item_meta'][249]; //Change 249 to the field containing the number of tickets being requested
$remaining_tickets = $_POST['item_meta'][281]; //Change 281 to the calculated field containing the number of remaining tickets
if( $tickets_requested > $remaining_tickets ) {
$errors[ 'field' . $field_id ] = "You've requested more tickets than available. Please try again";
}
@omniacode
omniacode / conditionally-enqueue-scripts.php
Created November 10, 2022 15:46
Conditionally Enqueue Scripts on Specific Page If It Is Not Already Enqueued
add_action( 'wp_enqueue_scripts', 'enqueue_my_custom_script' );
function enqueue_my_custom_script() {
if ( 'page' === get_post_type() && is_page('ID') ) {
if ( wp_script_is( 'file.js', 'enqueued' ) ) {
return;
} else {
wp_register_script( 'file name', get_stylesheet_directory_uri() . '/js/file.js' );
wp_enqueue_script( 'file name' );
}
}
@omniacode
omniacode / woo-change-user-role.php
Last active December 30, 2021 18:22
Change User Role Upon Product Purchase
<?php
// Single Product - Only Use One Snippet or the Other!!
function woo_change_role_after_purchase( $order_id ) {
// Get order object and items
$order = new WC_Order( $order_id );
$items = $order->get_items();
@omniacode
omniacode / remote-jquery-for-wordpress.php
Last active December 4, 2020 13:48
Use Repository Hosted jQuery for Wordpress
<?php
// Load jQuery from Google Lib
if( !is_admin()){
$url = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
$test_url = @fopen($url,'r');
if($test_url !== false) {
function load_external_jQuery() {
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', '', '', true );
wp_enqueue_script('jquery');
@omniacode
omniacode / exclude_product_cats_woocommerce.php
Created October 22, 2020 15:13
Exclude Specific Product Categories from WooCommerce Shop Page
// Exclude products from a particular category on the shop page
function ocs_custom_pre_get_posts_query( $q ) {
if( is_shop() || is_page('shop') ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'cat-1', 'cat-2', 'cat-3' ),
@omniacode
omniacode / custom_woocommerce_sorting_options.php
Last active October 22, 2020 15:09
Custom WooCommerce Sorting Options
// Fix Default WooCommerce Sorting
function ocs_remove_default_sorting_options( $options ){
unset( $options[ 'popularity' ] );
unset( $options[ 'menu_order' ] );
unset( $options[ 'rating' ] );
unset( $options[ 'date' ] );
unset( $options[ 'price' ] );
unset( $options[ 'price-desc' ] );
@omniacode
omniacode / cpt_registered_mod.php
Last active October 22, 2020 15:14
Modify Registered Custom Post Types Args
/**
* Filter the Products CPT to register more options.
*
* @param $args array The original CPT args.
* @param $post_type string The CPT slug.
*
* @return array
*/
function custom_permalink_mod( $args, $post_type ) {
// If not CPT, bail.
@omniacode
omniacode / change_woocommerce_return_to_shop_redirect
Created January 10, 2020 17:00
Change Resturn to Shop Redirect URL
/**
* Changes the redirect URL for the Return To Shop button in the cart.
*
* @return string
*/
function wc_empty_cart_redirect_url() {
return 'http://mywebsite.com/sample-page/';
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
@omniacode
omniacode / register_custom_post_type
Last active February 4, 2020 19:18
Register Custom Post Type
/*
* Define Project Custom Post Type
*
*
*/
add_action( 'init', 'register_my_custom_post_type' );
function register_my_custom_post_type() {
$cpt_singular = 'My Custom Post Type';
@omniacode
omniacode / custom-wp-excerpt.php
Last active October 26, 2018 13:08
Custom Wordpress Excerpt (Word Count)
<?php
add_filter( 'get_the_excerpt', 'custom_excerpt_length' );
function custom_excerpt_length( $content ) {
$length = 8;
$content = wp_trim_words( $content, $length, '...' );
return $content;
}
?>