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
// Reduce SearchWP's minimum character length to 2 (default is 3). | |
add_filter( 'searchwp\tokens\minimum_length', function( $min ) { | |
return 2; | |
} ); | |
/*--------------------*/ | |
/* support for parent/child products*/ | |
/* -------------------*/ | |
add_filter( 'searchwp\query\tokens', function( $terms, $query ){ | |
$exact_match = get_posts( array( |
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 WooCommerce Product (and Variation) SKUs to SearchWP. | |
// @link https://searchwp.com/documentation/knowledge-base/search-woocommerce-skus-and-variation-skus/ | |
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) { | |
// If this is not a Product, there's nothing to do. | |
if ( 'product' !== get_post_type( $entry->get_id() ) ) { | |
return $data; | |
} | |
$my_extra_meta_key = 'searchwp_skus'; |
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
// Allow partial regex pattern matches to be considered in SearchWP. | |
add_filter( 'searchwp\tokens\regex_patterns\only_full_matches', '__return_false' ); | |
// Enable regex pattern match tokenization in SearchWP. | |
add_filter( 'searchwp\tokens\tokenize_pattern_matches', '__return_true' ); | |
// Tell SearchWP to use a wildcard prefix when performing partial match logic. | |
add_filter( 'searchwp\query\partial_matches\wildcard_before', '__return_false' ); | |
// Tell SearchWP not to use a wildcard prefix when performing partial match logic. |
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
module.exports = async ({ page }) => { | |
await page.setRequestInterception(true); | |
page.on('request', (req) => { | |
if(req.resourceType() === 'image' ){ | |
req.abort(); | |
} | |
else { | |
req.continue(); |
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 that will check for user role and turn off VAT/tax for that role | |
*/ | |
function wc_diff_rate_for_user() { | |
// check for the user role | |
if ( ! is_user_logged_in() || current_user_can( 'customer' ) ) { |
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; |
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
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
<?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
/* | |
* 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 |
OlderNewer