Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikey Arce mikeyarce

View GitHub Profile
@mikeyarce
mikeyarce / order-downloads.php
Last active April 12, 2022 22:42
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 September 12, 2020 06:29
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 November 7, 2019 17:33
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 November 4, 2019 16:30
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 March 13, 2020 18:28
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 ) {
@mikeyarce
mikeyarce / launch.json
Created August 21, 2018 15:40
vs code xdebug
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 July 30, 2018 16:05
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 July 30, 2018 16:03
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 April 18, 2018 00:05
Override WooCommerce Gallery Thumbnail
View gallery-thumbnail.php