Skip to content

Instantly share code, notes, and snippets.

@mikeyarce
mikeyarce / order-downloads.php
Last active Feb 19, 2021
Show filename in WooCommerce Downloads Page
View order-downloads.php
<?php
/**
*
* This template has been modified to show the filename along with the title for each download
* Example: Download - filename.jpg
*
* Order Downloads.
*
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-downloads.php.
*
@mikeyarce
mikeyarce / max-quantities-woocommerce.php
Created Sep 12, 2020
Set a maximum quantity for a product in WooCommerce
View max-quantities-woocommerce.php
<?php // only add this line if it's at the top of a new PHP file
add_filter( 'woocommerce_add_to_cart_validation', 'validate_add_to_cart_action', 10, 3 );
function validate_add_to_cart_action( $valid, $product_id, $quantity ) {
// Set the product ID for the product you want to limit
$check_product_id = 121;
// We want to check two quantities, the current cart and how many you are currently adding. We're going to be adding them together into one variable called total_quantity.
$total_quantity = $quantity;
$maximum_quantity = 2;
@mikeyarce
mikeyarce / disable-wp-search.php
Last active Nov 7, 2019
Disable WordPress Search #core
View disable-wp-search.php
<?php
function ma_vip_unresolve_search() {
global $wp_query;
if ( $wp_query->is_search ) {
$wp_query->is_404 = true;
}
}
add_action( 'template_redirect', 'ma_vip_unresolve_search' );
@mikeyarce
mikeyarce / vip_jetpack_search_es_query_args.php
Last active Nov 4, 2019
Modify ES query argument for Jetpack Search
View vip_jetpack_search_es_query_args.php
<?php
add_filter( 'jetpack_search_es_query_args', function( $args, $query ) {
$args['date_range'] = array(
'field' => 'date',
'gte' => '2016-01-01',
'lte' => '2016-12-31',
);
return $args;
}, 10, 2 );
View jetpack-search-fuzzy.php
<?php
// Fuzzy search
add_filter( 'jetpack_search_es_query_args', 'es_fuzzy_search', 10, 2);
function es_fuzzy_search( $es_query_args, $query ) {
$query = get_search_query();
$es_query_args['query']['function_score']['query']['bool'] = array(
'must' => array(
array(
'multi_match' => array(
@mikeyarce
mikeyarce / vipgo-remove-jp-stas.php
Last active Mar 13, 2020
Disable and hide Jetpack Stats module
View vipgo-remove-jp-stas.php
<?php
// Disable the Stats Jetpack Module
add_filter( 'jetpack_active_modules', 'vipgo_override_jp_modules', 99, 9 );
function vipgo_override_jp_modules( $modules ) {
$disabled_modules = array(
'stats',
);
foreach ( $disabled_modules as $module_slug ) {
View launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": { "/var/www/wp-content": "${workspaceRoot}/" },
"port": 9000
},
@mikeyarce
mikeyarce / storefront-before-header-hook.php
Created Jul 30, 2018
Add content to Storefront "before header" hook
View storefront-before-header-hook.php
<?php
add_filter('storefront_before_header', function() {
echo 'Hello';
});
@mikeyarce
mikeyarce / storefront-homepage-product-categories.php
Created Jul 30, 2018
Storefront: change homepage product categories
View storefront-homepage-product-categories.php
<?php
// Hooking into the storefront_product_categories_args hook
add_filter( 'storefront_product_categories_args', 'marce_filter_homepage_product_categories_storefront', 11 );
// We're changing the values of limit, columns, and title for the Product Categories homepage section.
function marce_filter_homepage_product_categories_storefront( $args ) {
$args['limit'] = 1;
$args['columns'] = 4;
$args['title'] = 'Shop Categories';
@mikeyarce
mikeyarce / gallery-thumbnail.php
Created Apr 18, 2018
Override WooCommerce Gallery Thumbnail
View gallery-thumbnail.php