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 / woocommerce-add-custom-text-to-product-id-variation-area.php
Created May 9, 2018 12:52
WooCommerce | Add custom text to a particular product ID variation area
<?php
//hook our function to the product variation
add_action( 'woocommerce_single_variation', 'fs_custom_variation_text', 18 );
function fs_custom_variation_text() {
global $product;
// checking if the product is the correct product id
if ($product->id === 454) {
@Garconis
Garconis / woocommerce-admin-columns-pro-array.php
Last active February 21, 2024 21:14
Admin Columns Pro | Overwrite an Order column with values from a FooEvents Attendee array
<?php
/**
* Filter the display value for a column
*
* @param mixed $value Custom field value
* @param int $id Object ID
* @param AC_Column $column Column instance
*/
function ac_my_custom_field_column_value_example( $value, $id, $column ) {
@Garconis
Garconis / wordpress-create-shortcode-of-link-with-date-and-user-role.php
Created May 17, 2018 15:02
WordPress | Create a shortcode of a link based on hashed date and user role
@Garconis
Garconis / ultimate-member-force-allow-admin-access.php
Created May 18, 2018 18:11
Ultimate Member | Force allow any user to get access to WP Admin
<?php
/* ---
By default, Ultimate Member prevents backend access unless explicitily allowed via each role
In fact, if they have NUMEROUS roles, and only ONE of those roles was explicitiy given backend permission, the user still won't have access since their other roles are restricting it
So we take THEIR OWN FUNCTION and remove it. So now it won't matter if the UM role has "wp-admin" access or not.
--- */
function remove_um_admin_block_action() {
remove_action('init','um_block_wpadmin_by_user_role',99);
}
add_action('init','remove_um_admin_block_action');
@Garconis
Garconis / woocommerce-allow-one-product-per-category-in-cart.php
Created May 23, 2018 20:29
WooCommerce | Limit one product per specific category in the cart at a time
<?php
// https://www.proy.info/woocommerce-allow-only-1-product-per-category/
// Allow only one(or pre-defined) product per category in the cart
// Alternatively, try plugin: https://wordpress.org/plugins/woo-cart-limit/
add_filter( 'woocommerce_add_to_cart_validation', 'allowed_quantity_per_category_in_the_cart', 10, 2 );
function allowed_quantity_per_category_in_the_cart( $passed, $product_id) {
$max_num_products = 1;// change the maximum allowed in the cart
$running_qty = 0;
@Garconis
Garconis / wordpress-custom-post-type-shortcode-loop.php
Last active June 1, 2018 17:39
WordPress | Shortcode to output a loop of content of a custom post type
<?php
// create shortcode to list all Featured Itineraries
add_shortcode( 'all-featured-itineraries', 'fs_all_featured_itineraries_shortcode' );
function fs_all_featured_itineraries_shortcode( $atts ) {
ob_start();
// Query posts from the database.
$options = array(
// Arguments for your query.
'post_type' => 'collections',
@Garconis
Garconis / .htaccess
Created June 15, 2018 13:05
WordPress | Use htaccess to block logged-out users from certain folders or files
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in [NC]
RewriteRule (^|/)uploads/private/.+?\.(.*)$ login/?redirect_to=/portal/ [R,L]
</IfModule>
@Garconis
Garconis / enter-on-input-to-click-another-input.html
Last active June 27, 2018 15:11
jQuery | Pressing "Enter" in one input will cause another input to be clicked
<script>
jQuery(function() {
jQuery('.wpk-chmura form input[name="title"]').keypress(function(e) {
var key = e.which;
// the enter key code
if (key == 13) {
jQuery('.wpk-chmura form input[type="button"]').click();
return false;
}
@Garconis
Garconis / wordpress-exclude-posts-from-main-blog-if-has-certain-tag.php
Created June 27, 2018 20:10
WordPress | Remove post from main blog loop if it has a certain Tag
<?php
/**
* https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
* On the page that is set to be the blog homepage (Posts Page), exclude a post from the loop, if it has a certain tag ID
**/
// exclude posts from the main blog loop, if it has the Focus tag
function fs_exclude_specific_tag( $query ) {
if ( !is_admin() && $query->is_home() && $query->is_main_query() ) {
// $query->set( 'tag', '-141' );
@Garconis
Garconis / wordpress-cpt-slug-rewrite.php
Created June 29, 2018 16:58
WordPress | Forcing rewrite of CPT post based on the selected taxonomy term
<?php
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
* @author Michael Fields http://wordpress.mfields.org/
* @props John P. Bloch http://www.johnpbloch.com/
* @props Evan Mulins https://circlecube.com/circlecube/
*
* @since 2010-09-13
* @alter 2013-01-31