Skip to content

Instantly share code, notes, and snippets.

View qant's full-sized avatar
💫
Permanent study state

Anton qant

💫
Permanent study state
View GitHub Profile
@qant
qant / curl_vs_getheaders.php
Created April 16, 2021 10:56
cURL vs get_headers() Speed Test
<?php
// Get headers for 100 unique random domains with get_headers() and cURL to determine which is faster.
/*
TL;DR -> cURL is significantly faster.
get_headers (GET) vs cURL:
Execution time : 139.95884609222 seconds
Execution time : 65.998840093613 seconds
@qant
qant / woo-events.js
Created May 29, 2021 08:51 — forked from bagerathan/woo-events.js
Woocommerce Javascript events #woocommerce
//Woocommerce Checkout JS events
$( document.body ).trigger( 'init_checkout' );
$( document.body ).trigger( 'payment_method_selected' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_checkout' );
$( document.body ).trigger( 'checkout_error' );
//Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' );
$( document.body ).trigger( 'update_checkout' );
@qant
qant / lenura_empty_cart_before_add.php
Created May 29, 2021 11:48 — forked from viniciusrtf/lenura_empty_cart_before_add.php
WooCommerce Hook: Empty cart before adding a new product to cart WITHOUT throwing woocommerce_cart_is_empty
<?php
/**
* Hook: Empty cart before adding a new product to cart WITHOUT throwing woocommerce_cart_is_empty
*/
add_action ('woocommerce_add_to_cart', 'lenura_empty_cart_before_add', 0);
function lenura_empty_cart_before_add() {
global $woocommerce;
// Get 'product_id' and 'quantity' for the current woocommerce_add_to_cart operation
@qant
qant / composer.json
Created October 12, 2021 12:06
Excel and pdf example using php
{
"require": {
"phpoffice/phpspreadsheet": "^1.18",
"mpdf/mpdf": "^8.0"
}
}
@qant
qant / login_and_redirect_back.php
Created December 2, 2021 13:06
If not logged in. Redirect back to previous url, after login to the WordPress
<?php
//.... load wordpress stuff etc
if(!is_user_logged_in()) {
wp_redirect( wp_login_url($_SERVER['SCRIPT_URI']) );
}
@qant
qant / package.json
Created December 14, 2021 15:12
Resize and watermark images node
{ "name": "resize_and_watermark_images", "version": "1.0.0", "description": "", "main": "resize.js", "author": "Anton Semenov", "license": "", "dependencies": { "sharp": "^0.29.3" } }
@qant
qant / tax.php
Created February 8, 2022 07:45
Extra taxes woo
<?php
// Display the custom checkbow field in checkout
add_action( 'woocommerce_review_order_before_order_total', 'fee_installment_checkbox_field', 20 );
function fee_installment_checkbox_field(){
echo '<tr class="packing-select"><th>';
woocommerce_form_field( 'installment_fee', array(
'type' => 'checkbox',
'class' => array('installment-fee form-row-wide'),
'label' => __('Montaža v 14 dneh (predpripravljen prostor) - 170€'),
@qant
qant / woocommerce-popular-products.php
Created March 24, 2022 08:23 — forked from aslamdoctor/woocommerce-popular-products.php
Woocommerce : Get popular products using wp_query
@qant
qant / gist:8ee09e9ab5b79fcfa3e32790f5e0ab85
Created April 9, 2022 09:15
Clear all cart sessions woocommerce
//Using wp cli
wp wc tool run clear_sessions --user=1
Useful related commands: https://github.com/woocommerce/woocommerce/wiki/WC-CLI-Overview#command-1
wp wc tool run delete_orphaned_variations --user=1
wp wc tool run clear_expired_transients --user=1
wp wc tool run clear_transients --user=1
--user=1 is an admin user with ID=1 in my case
@qant
qant / filter.php
Created May 7, 2022 07:13 — forked from cfxd/filter.php
Efficient Responsive Images in WordPress. See https://cfxdesign.com/efficient-responsive-images-in-wordpress
<?php
/*
* THE FILTER
*
*/
function custom_responsive_image_sizes($sizes, $img_name, $attachment_id) {
$sizes = wp_get_attachment_image_sizes($attachment_id, 'original');
$meta = wp_get_attachment_metadata($attachment_id);
$width = $meta['width'];