This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' ), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' ] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_the_excerpt', 'custom_excerpt_length' ); | |
function custom_excerpt_length( $content ) { | |
$length = 8; | |
$content = wp_trim_words( $content, $length, '...' ); | |
return $content; | |
} | |
?> |
NewerOlder