Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pablo-sg-pacheco's full-sized avatar

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

View GitHub Profile
@pablo-sg-pacheco
pablo-sg-pacheco / main-plugin-file.php
Last active December 19, 2022 21:23
Custom deactivation/activation hooks from a WordPress plugin that can be called from some other hooks
<?php
// Custom deactivation/activation hooks.
$activation_hook = 'plugin_prefix_on_activation';
$deactivation_hook = 'plugin_prefix_on_deactivation';
register_activation_hook( __FILE__, function () use ( $activation_hook ) {
add_option( $activation_hook, 'yes' );
} );
register_deactivation_hook( __FILE__, function () use ( $deactivation_hook ) {
do_action( $deactivation_hook );
} );
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active February 3, 2021 15:55
WordPress - Convert array to string
<?php
/**
* converts array to string.
*
* @param $arr
* @param array $args
*
* @return string
*/
function convert_array_to_string( $arr, $args = array() ) {
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created August 13, 2020 20:28
Change WooCommerce Coupon amount on the fly (programmatically)
<?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 June 8, 2020 17:29
Booster for WooCommerce - Get info from Prices and Currencies by Country Module Options
<?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 January 31, 2020 18:10
Delete WordPress Transients by Prefix
<?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 October 11, 2019 19:46 — forked from TimBHowe/functions.php
Forcibly remove the tax line item and calculation from the cart. (suggest just using the GEO setting in WooCommerce)
<?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 November 5, 2018 18:33
Product Input Fields for WooCommerce - Display fields one above the other
<tr><td><div><label for="%field_id%">%title%</label></div>%field%</td></tr>
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active October 23, 2018 21:53
Product Open Pricing (Name Your Price) for WooCommerce - Add to cart programmatically
<?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 June 28, 2018 21:49
Customizes frontend position of Product Input field plugin
<?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 June 21, 2018 15:58
Replace input field by dropdown using the Product Open Pricing plugin
<?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;
}