Skip to content

Instantly share code, notes, and snippets.

@cristacheda
cristacheda / woo_shipping_functions.php
Created February 26, 2025 09:30
WooCommerce extra fee for cash on delivery cod payment
<?php
// A fee of 5 USD is charged for payment processing by the courier.
add_action( 'woocommerce_cart_calculate_fees', function() {
$cod_fee = 4.202; // no VAT value
$chosen_gateway = WC()->session->get( 'chosen_payment_method' );
if ( $chosen_gateway == 'cod' ) { // 'cod' stands for Cash on Delivery
$chosen_shipping_methods = wc_get_chosen_shipping_method_ids();
@cristacheda
cristacheda / woo_shipping_functions.php
Created February 26, 2025 09:28
WooCommerce hide shipping rates when free shipping is available, but allow local pickup if the order qualifies for free shipping
<?php
/**
* Hide shipping rates when free shipping is available, but allow local pickup if the order qualifies for free shipping.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function woo_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@cristacheda
cristacheda / gravity-forms-gclid-params-on-submit.js
Created February 23, 2024 18:25 — forked from Garconis/gravity-forms-gclid-params-on-submit.js
Gravity Forms | Log a parameter value to local storage and send with Gravity Form entry, such as Google Ads GCLID or other params
// get parameters of URL
function getParam(p) {
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
// set expiration date
function getExpiryRecord(value) {
var expiryPeriod = 90 * 24 * 60 * 60 * 1000; // 90 day expiry in milliseconds
var expiryDate = new Date().getTime() + expiryPeriod;
<?php
//elementor pro fontawesome fix
if ( ! is_plugin_active('elementor-pro/elementor-pro.php') ) return;
function replace_font_awesome_pro( $settings ) {
$json_url = ELEMENTOR_PRO_ASSETS_URL . 'lib/font-awesome-pro/%s.js';
$icons['fa-regular'] = [
'name' => 'fa-regular',
'label' => __( 'Font Awesome - Regular Pro', 'elementor-pro' ),
@cristacheda
cristacheda / update-tax-status.sql
Created March 18, 2021 14:25 — forked from BFTrick/update-tax-status.sql
Update the tax status of all WooCommerce products.
UPDATE `wp_postmeta`
SET meta_value='taxable'
WHERE meta_key='_tax_status'
<?php
if(!function_exists('wc_get_products')) {
return;
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
@cristacheda
cristacheda / dozens.js
Created November 26, 2019 10:14
Adaugă "de" la sfârșitul unui număr dacă este cazul.
var date = new Date('November 09 2019');
var current_day = date.getDate();
var base_forms = 5;
var forms = base_forms + current_day * 12;
var dozens = forms / 100;
var dozens = dozens.toString();
var dozens = dozens.split(".")[1];
var dozens = parseInt(dozens, 10);
if (dozens > 19) {
var forms = forms.toString() + ' de';
@cristacheda
cristacheda / tawkto-gtagjs.html
Last active January 27, 2022 14:47
Track Tawk.to chats, send events to Google Analytics, gtag.js implementation
<!--Start of Tawk.to Script-->
<script type="text/javascript">
// Load Tawk.to script
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src="https://embed.tawk.to/REPLACE-WITH-YOUR-TAWK-TO-ID/default";
s1.charset="UTF-8";
s1.setAttribute("crossorigin","*");
@cristacheda
cristacheda / test
Last active May 9, 2019 11:18
letters to numbers
function letterValue(str){
var anum={
a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 11,
l: 12, m: 13, n: 14,o: 15, p: 16, q: 17, r: 18, s: 19, t: 20,
u: 21, v: 22, w: 23, x: 24, y: 25, z: 26
}
if(str.length== 1) return anum[str] || ' ';
return str.split('').map(letterValue);
}
letterValue('dragos');
@cristacheda
cristacheda / Advanced Custom Fields repeater values to a Gravity Forms dropdown field.md
Last active August 26, 2022 03:47
Populate Gravity Forms dropdown field with Advanced Custom Fields repeater values.

Add Advanced Custom Fields repeater values to a Gravity Forms dropdown field

The code should be added in a separate file and then included in your functions.php using require.

Replace 1 from the code with the ID of the form that you want to dinamically populate with field values from ACF. You can find more info about the filters in the Gravity Forms documentation.

add_filter( 'gform_pre_render_1', 'populate_dropdown' );
add_filter( 'gform_pre_validation_1', 'populate_dropdown' );
add_filter( 'gform_admin_pre_render_1', 'populate_dropdown' );
add_filter( 'gform_pre_submission_filter_1', 'populate_dropdown' );