Skip to content

Instantly share code, notes, and snippets.

View SiR-DanieL's full-sized avatar

Nicola Mustone SiR-DanieL

View GitHub Profile
@SiR-DanieL
SiR-DanieL / style.css
Created November 28, 2023 16:56
What is Your WordPress Pet Peeve?
View style.css
body {
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active November 7, 2023 08:18
Streamline Your WooCommerce Store with Automatic EU VAT Validation
View functions.php
<?php
add_action( 'woocommerce_checkout_process', 'automatic_validation_eu_vat' );
function automatic_validation_eu_vat() {
$vat = str_replace( array( ' ', '.', '-', ',', ',' ), '', wc_clean( $_POST['billing_vat'] ) );
if ( ! empty( $vat ) ) {
$response = wp_remote_get( "http://ec.europa.eu/taxation_customs/vies/vatResponse.html?ms=" . substr( $vat, 0, 2 ) . "&iso=" . substr( $vat, 2 ) );
if ( is_wp_error( $response ) ) {
wc_add_notice( 'There was a problem connecting to the VAT validation service. Please try again later.', 'error' );
} else {
@SiR-DanieL
SiR-DanieL / functions.php
Created November 7, 2023 07:36
How to Disable GTIN Requirements for Non-Eligible WooCommerce Products
View functions.php
<?php
add_filter( 'woocommerce_structured_data_product', 'conditional_identifier_exists_false', 10, 2 );
function conditional_identifier_exists_false( $markup, $product ) {
// Replace 'your-category-slug' with the actual slug of the category you want to target.
$target_category_slug = 'your-category-slug';
if ( has_term( $target_category_slug, 'product_cat', $product->get_id() ) ) {
$markup['identifier_exists'] = 'no';
}
@SiR-DanieL
SiR-DanieL / functions.php
Created November 7, 2023 07:33
How to Disable GTIN Requirements for Non-Eligible WooCommerce Products
View functions.php
<?php
add_filter( 'woocommerce_structured_data_product', 'add_identifier_exists_false' );
function add_identifier_exists_false( $markup ) {
$markup['identifier_exists'] = 'no';
return $markup;
}
@SiR-DanieL
SiR-DanieL / functions.php
Created November 7, 2023 06:40
How to Make Your Edit Order Screen More Efficient
View functions.php
<?php
add_action( 'woocommerce_after_order_itemmeta', 'admin_order_add_product_info_and_link', 10, 3 );
function admin_order_add_product_info_and_link( $item_id, $item, $_product ) {
if ( ! $_product ) return;
$product_link = get_permalink( $_product->get_id() );
$attributes_to_display = ['slug_1', 'slug_2', 'slug_3']; // Specify the attribute slugs you want to display
$target_product = $_product;
if ($_product->is_type('variation')) {
@SiR-DanieL
SiR-DanieL / functions.php
Created October 30, 2023 10:31
Change the “Add to Cart” text on the single product page
View functions.php
<?php
// Change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_add_to_cart_text' );
function change_add_to_cart_text() {
return 'Add to Bag';
}
@SiR-DanieL
SiR-DanieL / functions.php
Created October 30, 2023 05:21
Change the Add to Cart text in WooCommerce
View functions.php
<?php
// Change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_add_to_cart_text' );
function change_add_to_cart_text() {
return 'Add to Bag';
}
// Change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'change_add_to_cart_text_archives' );
function change_add_to_cart_text_archives() {
View functions.php
<?php
// Predefined email address
define('HIDDEN_EMAIL_ORDERS', 'email@tohide.com');
// Add the checkbox
function add_email_filter_checkbox() {
global $typenow;
if ( 'shop_order' == $typenow ) {
$is_checked = isset( $_GET['hide_specific_email'] ) ? 'checked' : '';
@SiR-DanieL
SiR-DanieL / functions.php
Created October 30, 2023 04:39
Hide orders by email
View functions.php
<?php
// Filter orders based on the entered email
function filter_orders_by_emails( $query ) {
global $typenow, $wpdb;
if ( 'shop_order' == $typenow && isset( $_GET['filter_emails'] ) && !empty( $_GET['filter_emails'] ) ) {
$emails = array_map('sanitize_email', explode(',', $_GET['filter_emails']));
$order_ids = $wpdb->get_col( "SELECT pm.post_id FROM {$wpdb->postmeta} pm WHERE pm.meta_key = '_billing_email' AND pm.meta_value IN ('" . join("','", $emails) . "')" );
@SiR-DanieL
SiR-DanieL / functions.php
Created October 30, 2023 04:38
Add Email Filter
View functions.php
<?php
// Add the input field
function add_email_filter() {
global $typenow;
if ( 'shop_order' == $typenow ) {
$current_emails = isset( $_GET['filter_emails'] ) ? sanitize_text_field( $_GET['filter_emails'] ) : '';
echo '<input type="text" name="filter_emails" placeholder="Hide orders by email" value="' . esc_attr( $current_emails ) . '">';
}
}