Skip to content

Instantly share code, notes, and snippets.

View apsolut's full-sized avatar
🎯
Focusing

Aleksandar Perisic apsolut

🎯
Focusing
View GitHub Profile
@apsolut
apsolut / functions.php
Created December 23, 2015 15:59 — forked from kloon/functions.php
WooCommerce set tax exemption based on user role
<?php
add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesaler') || current_user_can('distributor') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
@apsolut
apsolut / gist:5a3e55528a66161ffcfe
Created January 6, 2016 18:51 — forked from getdave/gist:4578295
Gravity Forms - custom field validation function for checkboxes. Ensures all checkboxes have been checked.
// Replace 7 with the ID of your form and 13 with the ID of the field you want to force "all required"
// http://www.gravityhelp.com/documentation/page/Gform_field_validation
add_filter("gform_field_validation_7_13", 'validate_tcs', 10, 4);
function validate_tcs($result, $value, $form, $field) {
// Convert the checkbox input name value (returned as part of "field")
// into the "underscored" ID version which is found in the $_POST
foreach ($field['inputs'] as $input) {
$input_post_value = 'input_' . str_replace('.', '_', $input['id']);
<?php
/**
*
* Decom Custom Functions
* Extend and Make Future Proof
* Just sample file - use filter for real cases
* @package Decom
* @registration field
* Email notifications
*/
@apsolut
apsolut / wp_migrate.md
Created May 4, 2016 16:12 — forked from messified/wp_migrate.md
WordPress DB Migration Queries

Useful WordPress Queries

Site / Home URLs

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Update content Guid

@apsolut
apsolut / rename-layered-string.php
Last active May 17, 2016 12:31
class-wc-widget-layered-nav.php#L215
<?php
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
* @link https://github.com/woothemes/woocommerce/blob/master/includes/widgets/class-wc-widget-layered-nav.php#L215
* @link http://speakinginbytes.com/2013/10/gettext-filter-wordpress/
*/
function translate_string_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
@apsolut
apsolut / woocommerce_payment_changes.php
Created May 12, 2016 10:41
woocommerce_available_payment_gateways
function decom_paypal_disable_manager( $available_gateways ) {
global $woocommerce;
$user = wp_get_current_user();
if ( isset( $available_gateways['cheque'] ) && (in_array( 'customer', $user->roles ) || in_array( 'client', $user->roles) || in_array( 'klingon', $user->roles) )) {
//unset( $available_gateways['cheque'] );
}
else if ( isset( $available_gateways['paypal'] ) && ( in_array( 'wholesale', $user->roles ) || in_array( 'retailer', $user->roles) ) ) {
unset( $available_gateways['paypal'] );
}
/*
* Array
*/
array(
'customer_processing_order',
'customer_completed_order',
'customer_order_confirmation', //germanmarket
'cancelled_order',
'customer_invoice',
'customer_note',
@apsolut
apsolut / wp-gallery-mixin.scss
Last active June 3, 2016 16:49
WordPress Gallery mixin example
@apsolut
apsolut / woo-outofstock.php
Created June 20, 2016 00:29
WOO - Display only outofstock products
<?php
$outofstock_arg = array(
'post_type' => array('product', 'product_variation'), //'product', 'product_variation'
'post_status' => 'publish',
'meta_query' => array(
// https://github.com/woothemes/woocommerce/blob/master/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
array(
'key' => '_stock_status',
'value' => 'outofstock', //instock
'compare' => 'IN'
@apsolut
apsolut / gist:20a6008185dd3470110b7364a75a3248
Last active July 11, 2016 10:55
Loop meta query and custom post type
<!-- custom post type and acf field + -->
<?php
$topdate = date('Y-m-d H:i:s');
$main_match_arg = array(
'post_type' => 'matches',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'decom_match_categories',