Trigger Variation Image Change After Color Change (WooCommerce)

(function ($) { $(document).ready(function ($) { var variations = JSON.parse( jQuery(“.variations_form”).attr(“data-product_variations”) ); if (variations) { var nthAttributeToSwitchImage = 1; var attributeName = Object.keys( variations[nthAttributeToSwitchImage – 1].attributes )[0]; // jQuery(“[name=” + attributeName + “]”).change(function () { jQuery(“.woocommerce div.product form.cart .variations select”).change(…Continue reading

Split Full Name at Checkout

document.addEventListener(‘DOMContentLoaded’, function () { // Select the First Name field var firstNameField = document.querySelector(‘#billing_first_name’); var lastNameField = document.querySelector(‘#billing_last_name’); if (firstNameField) { firstNameField.addEventListener(‘change’, function () { var fullName = firstNameField.value.trim(); var nameParts = fullName.split(‘ ‘); // Extract First Name and Last…Continue reading

Add the Buy on Kindle button near Add to Cart in WooCommerce PDP.

/** * Snippet Name: Add the Buy on Kindle button near Add to Cart in WooCommerce PDP. */ add_action(‘woocommerce_after_add_to_cart_button’,’add_kindle_button’); function add_kindle_button() { $kindle_button_url = get_post_meta( get_the_ID(),’kindle_button_url’,true); if ( isset($kindle_button_url) && filter_var($kindle_button_url, FILTER_VALIDATE_URL)) { $style = ‘style=”background-color: #ff9900; color: #fff;’; $button…Continue reading

Modify WooCommerce Coupon Message

add_filter( ‘woocommerce_coupon_message’, ‘modify_woocommerce_coupon_message’, 10, 3 ); function modify_woocommerce_coupon_message( $msg, $msg_code, $coupon ) { if( $msg === __( ‘Coupon code applied successfully.’, ‘woocommerce’ ) ) { $msg = sprintf( __( “You are getting $%s discounts.”, “woocommerce” ), ‘‘ . $coupon->get_amount() .…Continue reading

Exclude Product From Discount Coupons in WooCommerce

/** * Snippet Name: Exclude Product From Discount Coupons. */ add_filter( ‘woocommerce_coupon_is_valid_for_product’, ‘exclude_product_from_product_promotions’, 999, 4 ); function exclude_product_from_product_promotions( $valid, $product, $coupon, $values ) { // Product id here (i.e. 123) if ( 123 == $product->get_id() ) { $valid = false;…Continue reading

Apply discount on the cheapest item in WooCommerce

/** * Snippet Name: Apply discount on the cheapest item */ add_action( ‘woocommerce_before_calculate_totals’, ‘apply_discount_on_cheapest_item’, 999 ); function apply_discount_on_cheapest_item( $cart ) { if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return; if ( did_action( ‘woocommerce_before_calculate_totals’ ) >= 2 ) return;…Continue reading