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
@echo off | |
rem sourced from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file | |
setlocal enabledelayedexpansion | |
set INTEXTFILE=test.txt | |
set OUTTEXTFILE=test_out.txt | |
set SEARCHTEXT=bath | |
set REPLACETEXT=hello | |
set OUTPUTLINE= | |
for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do ( |
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
#!/bin/bash | |
currentAttempt=0 | |
totalAttempts=10 | |
delay=15 | |
while [ $currentAttempt -lt $totalAttempts ] | |
do | |
currentAttempt=$(( $currentAttempt + 1 )) | |
echo "Attempt $currentAttempt of $totalAttempts..." |
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
def update(dl_url, force_update=False): | |
""" | |
Attempts to download the update url in order to find if an update is needed. | |
If an update is needed, the current script is backed up and the update is | |
saved in its place. | |
""" | |
import urllib | |
import re | |
from subprocess import call | |
def compare_versions(vA, vB): |
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 | |
function filter_the_posts($posts, &$wp_query) { | |
if( is_search() ) | |
{ | |
//make array of product ids | |
$ids = array(); | |
foreach ($posts as $key => $post) | |
{ | |
$ids[$post->ID] = $post->ID; |
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 | |
//Exclude child products from searches | |
function my_searchwp_exclude( $ids, $engine, $terms ){ | |
$excluded_product_ids = get_posts( array( | |
'post_type' => 'product', | |
'nopaging' => true, | |
'fields' => 'ids', | |
'meta_query' => array( | |
array( | |
'key' => '_children', |
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
/* | |
* Example adds certain named Product Attribute fields to the product Edit screen ready for completion. | |
* (Pre-requisite ) | |
* This saves the Shop Admin having to add them manually. | |
* | |
* Why might you want to do this instead of adding Custom fields? There's plenty of nice documentation on adding custom fields | |
* for example: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ | |
* | |
* Well a Product Attributes are a built in WooCommerce feature, using Terms which are a built in Wordpress feature. | |
* - no add-ons required |
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 | |
function my_get_product_id_by_sku( $sku = false ) { | |
global $wpdb; | |
if( !$sku ) | |
return null; | |
$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) ); |
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
function my_searchwp_pre_search_terms( $terms, $engine ) { | |
$exact_match = get_posts( array( | |
'post_type' => 'product', | |
'nopaging' => true, | |
'fields' => 'ids', | |
'meta_query' => array( | |
array( | |
'key' => '_sku', | |
'value' => $terms, |
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_filter( 'facetwp_pager_html', function( $output, $params ) { | |
// show all pages | |
/* | |
$output = ''; | |
if ( 1 < $params['total_pages'] ) { | |
for ( $i = 1; $i <= $params['total_pages']; $i++ ) { | |
$is_curr = ( $i === $params['page'] ) ? ' active' : ''; | |
$output .= '<a class="facetwp-page' . $is_curr . '" data-page="' . $i . '">' . $i . '</a>'; |
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( 'woocommerce_package_rates', 'custom_shipping_costs', 20, 2 ); | |
function custom_shipping_costs( $rates, $package ) | |
{ | |
// New shipping cost (can be calculated) | |
$new_cost = 5; | |
$tax_rate = 0.21; | |
global $woocommerce; |
NewerOlder