Skip to content

Instantly share code, notes, and snippets.

Avatar

Pablo dos Santos Gonçalves Pacheco pablo-sg-pacheco

View GitHub Profile
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created Aug 13, 2020
Change WooCommerce Coupon amount on the fly (programmatically)
View functions.php
<?php
add_filter('woocommerce_get_shop_coupon_data', 'fix_wc_coupon_discount_amount', 10, 3);
function fix_wc_coupon_discount_amount( $false, $data, $coupon ) {
if (
'yes' !== get_option( 'wcj_multicurrency_compatibility_wc_coupons', 'no' )
|| is_admin()
|| empty( $coupon_id = wc_get_coupon_id_by_code( $data ) )
|| 'fixed_cart' != get_post_meta( $coupon_id, 'discount_type', true )
) {
return $false;
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created Jun 8, 2020
Booster for WooCommerce - Get info from Prices and Currencies by Country Module Options
View functions.php
<?php
add_action('wp_footer',function(){
if ( !WCJ()->modules['price_by_country']->is_enabled() ) {
return;
}
$country = WCJ()->modules['price_by_country']->core->get_customer_country_by_ip();
$group = WCJ()->modules['price_by_country']->core->get_customer_country_group_id();
$the_result = array('country'=>$country,'group'=>$group);
?>
<script>
@pablo-sg-pacheco
pablo-sg-pacheco / wp-delete-transients-by-prefix.php
Last active Jan 31, 2020
Delete WordPress Transients by Prefix
View wp-delete-transients-by-prefix.php
<?php
/**
* Deletes transients that match a specific prefix.
*
* @author Pablo Pacheco <pablo.sg.pacheco@gmail.com>
* @param string $prefix prefix to search for.
* @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.
*/
function delete_transients_by_prefix($prefix){
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created Oct 11, 2019 — forked from TimBHowe/functions.php
Forcibly remove the tax line item and calculation from the cart. (suggest just using the GEO setting in WooCommerce)
View functions.php
<?php
// Remove the Tax Line item from the cart.
function wc_remove_cart_tax_totals( $tax_totals, $instance ) {
if( is_cart() ) {
$tax_totals = array();
}
return $tax_totals;
}
@pablo-sg-pacheco
pablo-sg-pacheco / Settings
Last active Nov 5, 2018
Product Input Fields for WooCommerce - Display fields one above the other
View Settings
<tr><td><div><label for="%field_id%">%title%</label></div>%field%</td></tr>
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active Oct 23, 2018
Product Open Pricing (Name Your Price) for WooCommerce - Add to cart programmatically
View functions.php
<?php
add_action('wp_loaded',function(){
if( is_admin() ){
return;
}
$product_id = 161;
$quantity = 1;
$variation_id = 0;
WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, array(), array(
'alg_open_price' => 99
@pablo-sg-pacheco
pablo-sg-pacheco / customize-pif-frontend-position.php
Created Jun 28, 2018
Customizes frontend position of Product Input field plugin
View customize-pif-frontend-position.php
<?php
/*
Plugin Name: Customize Product Input Field Frontend Position
Description: Customizes frontend position of Product Input Field plugin
Version: 1.0.0
Author: Algoritmika Ltd
Author URI: http://algoritmika.com
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Text Domain: customize-pif-frontend-position
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active Jun 21, 2018
Replace input field by dropdown using the Product Open Pricing plugin
View functions.php
<?php
// Remove default input
add_filter( 'option_' . 'alg_wc_product_open_pricing_frontend_template', 'popwc_remove_default_input' , 10, 2 );
function popwc_remove_default_input($value){
if(!is_admin()){
$value='';
}
return $value;
}
@pablo-sg-pacheco
pablo-sg-pacheco / index.php
Last active Jun 20, 2018
Add compatibility with WOOF plugin and More Sorting Options for WooCommerce regarding title sorting option
View index.php
<?php
// Add these cases on get_catalog_orderby() function on index.php
case 'title-desc':
$orderby = "title";
$order = 'DESC';
break;
case 'title-asc':
$orderby = "title";
$order = 'ASC';
@pablo-sg-pacheco
pablo-sg-pacheco / style.css
Last active May 8, 2018
Charity Theme - Move the mobile menu icon to center
View style.css
/*
* Move the mobile menu icon to center
*
* Theme Name: HB Charity
* Theme URI: http://hummingbirdthemes.com/themes/hb-charity-wordpress-theme/
*/
.menu .visible-xs{
text-align:center;
}
.menu #showbutton{
You can’t perform that action at this time.