Skip to content

Instantly share code, notes, and snippets.

View FrancoStino's full-sized avatar
🌞

Davide Ladisa FrancoStino

🌞
View GitHub Profile
@FrancoStino
FrancoStino / Show Description When Short Description Empty - WooCommerce.php
Last active January 17, 2021 19:33
Show Description When Short Description Empty - WooCommerce
<?
/**
* @snippet Show Description When Short Description Empty - WooCommerce
*/
add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_short_desc_if_empty', 21 );
remove_filter( 'the_excerpt', 'bbloomer_echo_short_desc_if_empty' );
/*add_filter( 'the_excerpt', 'bbloomer_echo_short_desc_if_empty' );*/
function bbloomer_echo_short_desc_if_empty() {
@FrancoStino
FrancoStino / Add suffix price through tax name with slug.php
Last active January 19, 2021 08:56
Add suffix price through tax name with slug
<?
/*
* Add suffix price through tax name with slug
*/
add_filter( 'woocommerce_available_variation', 'custom_variation_price', 10, 3 );
function custom_variation_price( $data, $product, $variation ) {
$price_excl_tax = (float) wc_get_price_excluding_tax( $variation ); // price without VAT
$price_incl_tax = (float) wc_get_price_including_tax( $variation ); // price with VAT
@FrancoStino
FrancoStino / Add Free shipping conditionally with specific category on cart and minimum order for this category.php
Last active January 26, 2021 14:41
Add Free shipping conditionally with specific category on cart and minimum order for this category
<?
/**
* Add Free shipping conditionally with certain category on cart and minimum order
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_flat_rate_conditionaly', 90, 2 );
function hide_shipping_flat_rate_conditionaly( $rates, $package ){
// HERE Define your product category (ID, slug or name or an array of values)
@FrancoStino
FrancoStino / Lets Shop Managers have the capability of editing and promoting users.php
Last active October 10, 2022 19:16
Lets Shop Managers have the capability of editing and promoting users
<?php
/* Lets Shop Managers have the capability of editing and promoting users */
function wws_add_shop_manager_user_editing_capability() {
$shop_manager = get_role( 'shop_manager' );
$shop_manager->add_cap( 'create_users' );
$shop_manager->add_cap( 'edit_users' );
$shop_manager->add_cap( 'edit_user' );
$shop_manager->add_cap( 'promote_users' );
$shop_manager->add_cap( 'delete_users' );
@FrancoStino
FrancoStino / Set a minimum order amount for checkout.php
Last active June 9, 2022 08:41
Set a minimum order amount for checkout
<?php
/**
* Set a minimum order amount for checkout
*/
add_action( 'woocommerce_before_checkout_form', 'wc_minimum_order_amount' );
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
@FrancoStino
FrancoStino / Send a new account registration email to a personalized email.php
Created February 16, 2021 09:20
Send a new account registration email to a personalized email
<?
/*
* Send a new account registration email to a personalized email
*/
add_action( 'user_register', 'so27450945_user_register', 10, 1 );
function so27450945_user_register( $user_id )
{
$user = get_user_by( 'id', $user_id );
@FrancoStino
FrancoStino / Additional Products Table Column (Gallery) and Display List of Products With No Gallery @ Admin All Product - WooCommerce.php
Last active January 14, 2022 14:33
Additional Products Table Column (Gallery) and Display List of Products With No Gallery @ Admin All Product - WooCommerce
@FrancoStino
FrancoStino / Merge 2 file TXT into one with separator.php
Last active February 26, 2021 08:52
Merge 2 file TXT into one with separator.php
<?
$files1 = file('Anagrafica_Articoli.txt'); // read file1.txt
$files2 = file('Livello1.txt', FILE_IGNORE_NEW_LINES); // read file2.txt
// Assuming both files have equal amount of rows.
for($x = 0; $x < count($files1); $x++) {
$files1[$x] = str_replace(array("\n", "\r"), "", $files1[$x]);
$files3[$x] = $files1[$x]."".$files2[$x];
}
$result = implode("|\n", $files3);
@FrancoStino
FrancoStino / install.php
Created February 26, 2021 08:13
A simple PHP script that automatically downloads and unzips file in the current directory.
<?php
echo '<pre>';
echo '<span style="color:blue">DOWNLOADING...</span>'.PHP_EOL;
// Download file
file_put_contents('prodotti.zip', file_get_contents('ftp://5100_stano:trHfD,[email protected]:21/dati/Anagrafiche.zip'));
$zip = new ZipArchive();
$res = $zip->open('prodotti.zip');
@FrancoStino
FrancoStino / install.php
Last active February 26, 2021 08:53
Merge multilple file TXT into one with separator.php
<?
$anagrafiche = file('Anagrafica_Articoli.txt'); // read
$livello1 = file('Livello1.txt', FILE_IGNORE_NEW_LINES); // read
$livello2 = file('Livello2.txt', FILE_IGNORE_NEW_LINES); // read
$livello3 = file('Livello3.txt', FILE_IGNORE_NEW_LINES); // read
$livello4 = file('Livello4.txt', FILE_IGNORE_NEW_LINES); // read
$livello5 = file('Livello5.txt', FILE_IGNORE_NEW_LINES); // read
// Assuming both files have equal amount of rows.
for($x = 0; $x < count($anagrafiche); $x++) {