Skip to content

Instantly share code, notes, and snippets.

Avatar

Robbert Langezaal opicron

View GitHub Profile
View scrape.js
module.exports = async ({ page }) => {
await page.setRequestInterception(true);
page.on('request', (req) => {
if(req.resourceType() === 'image' ){
req.abort();
}
else {
req.continue();
@opicron
opicron / vat.php
Created Jan 29, 2019
Tax - exempt guests and customers
View vat.php
<?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' ) ) {
@opicron
opicron / dropship.php
Last active Nov 10, 2020
Add dropshipment costs
View dropship.php
<?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;
@opicron
opicron / functions.php
Created Jan 15, 2019
facetwp custom pagination
View functions.php
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>';
@opicron
opicron / functions.php
Created Jan 10, 2019
searchwp custom code
View functions.php
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,
@opicron
opicron / woocommerce_sku_to_id.php
Last active Jan 7, 2019
change sku to id for woocommerce product table
View woocommerce_sku_to_id.php
<?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 ) );
@opicron
opicron / functions.php
Created Dec 14, 2018 — forked from Jon007/functions.php
Add default Product Attributes to all WooCommerce products
View functions.php
/*
* 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
@opicron
opicron / test.php
Last active Apr 10, 2018
SearchWP custom search grouped/child
View test.php
<?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',
View filter-search-results.php
<?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;