Skip to content

Instantly share code, notes, and snippets.

View FrancoStino's full-sized avatar
🌞

Davide Ladisa FrancoStino

🌞
View GitHub Profile
@FrancoStino
FrancoStino / remove-all-product-term-tag-attribute-and-categories-sql-woocommerce.sql
Last active July 4, 2023 13:16
Query SQL to delete, remove and clean all product, term, tag, attribute and categories - Woocommerce
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%');
DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%';
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
@FrancoStino
FrancoStino / prevents-the-addition-of-a-product-if-there-is-a-specific-product-in-the-cart-while-emptying-the-basket-leaving-the-specific-product-if-it-is-added-woocommerce.php
Created March 21, 2023 16:47
Prevents the Addition of A Product if There Is a Specific Product in The cart, While Emptying the Basket Leaving the Specific Product if It Is Added - Woocommerce
<?php
// Funzione che controlla se nel carrello c'è un prodotto specifico
add_filter( 'woocommerce_add_to_cart_validation', 'prevent_product_add_to_cart', 10, 3 );
function prevent_product_add_to_cart( $passed, $product_id, $quantity ) {
// set the product IDs that will prevent the addition of new products
$restricted_products = array( 1291 );
// check if any of the restricted products are already in the cart
@FrancoStino
FrancoStino / change-color-of-select-variation-after-alert-jquery-woocommerce.js
Created March 18, 2023 15:05
Change color of select variation after alert Jquery - Woocommerce
jQuery(document).ready(function($){
$('.single_add_to_cart_button, .wd-buy-now-btn').on("click change", function(e){
if ($('.variations select').val() === "") {
// e.preventDefault();
alert("Seleziona le opzioni del prodotto prima di aggiungerlo al carrello.");
$('.variations select').css({'color': 'red', 'border-color': 'red'});
$('option').css('color','initial');
return false;
}
});
@FrancoStino
FrancoStino / grey-out-out-of-stock-variations.php
Last active March 17, 2023 15:17
Grey-out Out of Stock Variations and Disable Out of Stock Variations - Woocommerce
<?php
// Disable out of stock variations @ WooCommerce Single
add_filter( 'woocommerce_variation_is_active', 'grey_out_variations_when_out_of_stock', 10, 2 );
function grey_out_variations_when_out_of_stock( $grey_out, $variation ) {
?>
<script type="text/javascript">
@FrancoStino
FrancoStino / menu-custom-data-attributes-wordpress-tag-a-nav-link.php
Last active March 10, 2023 14:16
Menu Custom Data Attributes Wordpress tag a nav link
@FrancoStino
FrancoStino / add-notify-me-when-available-waitlist-into-single-product-page-save-in-ajax-response-html-css-message-and-send-email-if-product-back-in-stock-using-wc-email-template-woocommerce.php
Last active August 26, 2024 08:10
Add "Notify Me When Available/Waitlist" Into Single Product Page, Save In Ajax, Response Html Css Message And Send Email If Product Back In Stock Using Wc Email Template - Woocommerce
<?php
/*
* Add "Notify Me When Available" - Woocommerce
*/
add_action( 'woocommerce_single_product_summary', 'cwpai_notify_me_when_available', 30 );
function cwpai_notify_me_when_available() {
global $product;
if ( ! $product->is_in_stock() ) {
@FrancoStino
FrancoStino / add-button-empty-clear-cart-into-cart-page-and-minicart-woocommerce.php
Last active May 25, 2023 13:25
Add button empty/clear cart into cart page and minicart - Woocommerce
<?php
// adds the button to the cart page
add_action( 'woocommerce_cart_actions', 'woocommerce_empty_cart_button' );
function woocommerce_empty_cart_button() {
echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'yes' ) ) . '" style="background-color: rgba(224, 32, 32,1);"; class="btn btn-scheme-light btn-scheme-hover-light btn-style-default btn-style-round btn-size-default" title="' . esc_attr( 'Svuota il carrello', 'woocommerce' ) . '">' . esc_html( 'Svuota il carrello', 'woocommerce' ) . '</a>';
}
// empty the cart and refresh the page (redirects to the cart page)
add_action( 'wp_loaded', 'woocommerce_empty_cart_action', 20 );
@FrancoStino
FrancoStino / hide-add-to-cart-for-certain-categories-woocommerce.php
Created January 13, 2023 15:49
Hide Add to cart for certain categories - Woocommerce
<?php
/**
* Replace 'Add to cart' button to link on Shop Page and Archive Pages if is Simple Product
*/
function my_replacing_add_to_cart_button( $button, $product ) {
$categories = array( 'pavimenti' );
@FrancoStino
FrancoStino / unhook-and-remove-woo-commerce-default-emails.php
Created January 4, 2023 11:53
Unhook and remove WooCommerce default emails
<?php
/**
* Unhook and remove WooCommerce default emails.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
@FrancoStino
FrancoStino / force-login-gestionale-woocommerce.php
Created January 4, 2023 11:52
Force Login Gestionale Woocommerce
<?php
function woo_login_redirect() {
if (! is_user_logged_in() && is_front_page() ) {
wp_redirect( wc_get_page_permalink( 'myaccount' ) );
exit;
}
}
add_action('template_redirect', 'woo_login_redirect');