Skip to content

Instantly share code, notes, and snippets.

@growdev
growdev / refund.php
Created June 14, 2021 21:10
Bulk Refund WooCommerce Orders using CSV file input.
<?php
/**
* Bulk Refund Orders
*
* This script expects a csv file with following columns:
* - Order ID 1002
* - Reason for refund 'Item was oversold.'
* - Amount to refund '34.56'
* - Refund payment true/false
* - Restock item true/false
@msaari
msaari / wp_remote_get_with_cache.php
Last active December 15, 2021 21:13
wp_remote_get_with_cache – Fetches remote data with dual-layer caching
<?php
/**
* Fetches remote data with dual-layer caching.
*
* Uses wp_remote_get to fetch remote data. The data is cached twice: it's
* stored in a transient and an option. The transient is used as the main cache
* but if the transient has expired and the remote site doesn't respond,
* backup data from the option is returned.
*
@msaari
msaari / intermediary.php
Last active March 28, 2023 13:52
Relevanssi attachment indexing server intermediary script
<?php
/**
* Attachment processing intermediary to work between Relevanssi and a Tika server.
*
* Installation instructions:
* 1. Save this as index.php.
* 2. Change the Tika server URL in the constructor to point to your own Tika server.
* 3. Upload this file in a directory on your server.
*
* @author Mikko Saari (mikko@mikkosaari.fi)
@sekanderb
sekanderb / add-more-to-cart.php
Created July 3, 2019 12:30
Adds the feature to add multiple products on WooCommerce Cart
class add_more_to_cart {
private $prevent_redirect = false; //used to prevent WC from redirecting if we have more to process
function __construct() {
if ( ! isset( $_REQUEST[ 'add-more-to-cart' ] ) ) return; //don't load if we don't have to
$this->prevent_redirect = 'no'; //prevent WC from redirecting so we can process additional items
add_action( 'wp_loaded', [ $this, 'add_more_to_cart' ], 21 ); //fire after WC does, so we just process extra ones
add_action( 'pre_option_woocommerce_cart_redirect_after_add', [ $this, 'intercept_option' ], 9000 ); //intercept the WC option to force no redirect
}
@temsool
temsool / Image ratio on featured image widget elementor.php
Created October 4, 2018 19:57
Image ratio on featured image widget elementor
@jchristopher
jchristopher / functions.php
Last active February 2, 2019 15:09
Use a supplemental engine when searching WooCommerce Orders. See https://searchwp.com/docs/kb/searching-woocommerce-orders/
<?php
/**
* When performing an admin search for WooCommerce Orders, use the 'Orders' SearchWP engine
*/
function my_searchwp_search_args( $args ) {
$search_in_admin = apply_filters( 'searchwp_in_admin', false );
if ( wp_doing_ajax() || empty( $_GET['post_type'] ) || ! is_admin() || empty( $search_in_admin ) ) {
return $args;
@YakovL
YakovL / creat_zip_download.php
Last active September 12, 2021 14:29 — forked from somatonic/creat_zip_download.php
create a zip file and send to browser
<?php
// this file is supposed to be in UTF-8 without BOM
function isRunningOnWindows() {
$os = php_uname('s'); //PHP_OS see https://stackoverflow.com/q/1482260/3995261
return preg_match('#win#i',$os) ? true : false;
}
function fixFilenameEncoding($name) {
// seemingly is needed on Windows only because filename encoding is not utf-8
return isRunningOnWindows() ? mb_convert_encoding($name, "windows-1251", "utf-8") : $name;
}
@saltnpixels
saltnpixels / gform_stripe_subscriptions.php
Created October 10, 2017 15:25
Gravity forms stripe cancel from front end
<?php
/**
* Payment subscriptions and updating billing and cancelling subscriptions takes place with these hooks
* We need the stripe customer user id for updating billing
* we need the entry id of subscription so we can cancel it.
*/
/**
* @param $entry
@robwent
robwent / disqus-ondemand.html
Last active September 9, 2021 07:59
Loads Disqus comments on click with native JavaScript. Opens comments when linked to directly.
<div class="comments-block">
<button id="show-comments" onclick="disqus();return false;">Load Comments</button>
</div>
<div id="disqus_thread"></div>
<script>
var disqus_loaded = false;
var disqus_shortname = 'xxxx'; //Add your shortname here
/* Add Image Stretch Option Control to the Image Gallery Widget */
add_action( 'elementor/element/before_section_end', function( $element, $section_id, $args ) {
/** @var \Elementor\Element_Base $element */
if ( 'image-gallery' === $element->get_name() && 'section_gallery' === $section_id ) {
$element->add_control(
'image_stretch',
[
'label' => __( 'Image Stretch', 'elementor' ),
'type' => \Elementor\Controls_Manager::SELECT,