Skip to content

Instantly share code, notes, and snippets.

View warnakey's full-sized avatar

warnakey

View GitHub Profile
@warnakey
warnakey / Prevent-Spam-Robot-From-Completing-WooCommerce-Orders-Based-On-City.php
Last active August 18, 2021 22:57
This code prevents Spam robots from completing orders on WooCommerce if they type the city field as 'dsfsdf' then kicks them off the website
/* You can put this in your footer.php file */
/* This code checks if Spam robots type the City field in the WooCommerce checkout page as 'dsfsdf' and kicks them out */
/* This can be modified to any condition you like by changing the if statements and event listeners around */
<?php if( $post->ID == 2309 ) { ?> // change this to your Checkout page's ID
<script>
// get variables for the different fields in the woocommerce checkout form (note 'billing' vs 'shipping' side)
var cityfield = document.getElementById('billing_city');
var postfield = document.getElementById('billing_postcode');
@warnakey
warnakey / WooCommerce-disable-UPS-shipping-options-if-shipping-to-a-PO-Box.php
Created August 20, 2021 06:16
Code for WooCommerce site to disable UPS shipping options if shipping to a PO Box (because UPS doesn't ship to PO Boxes)
<!-- You can add this to your footer.php file -->
<!-- UPS does'nt ship to PO Boxes, so if your site has multiple carriers (ex. USPS, FedEx & UPS) you would disable UPS for PO boxes -->
<!-- ** REPLACE ** the ID below to be the one for your WooCommerce checkout page !!!!!! -->
<?php if($post->ID == 2309) { // only works on checkout page ?>
<script>
// find the billing and shipping email fields to use for event listeners
// This code will fire when the customer clicks off of either email field
@warnakey
warnakey / force-wistia-embed-to-show-custom-poster.html
Last active September 4, 2021 18:37
Force Wistia Video Embeds to show a custom poster image, like a GIF
<div class="video" id="customvideo">
<script src="https://fast.wistia.com/embed/medias/ugydl9lr6t.jsonp" async></script><script src="https://fast.wistia.com/assets/external/E-v1.js" async></script><div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;"><div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;"><div class="wistia_embed wistia_async_ugydl9lr6t videoFoam=true" style="height:100%;position:relative;width:100%"><div class="wistia_swatch" style="height:100%;left:0;opacity:0;overflow:hidden;position:absolute;top:0;transition:opacity 200ms;width:100%;"><img src="https://fast.wistia.com/embed/medias/ugydl9lr6t/swatch" style="filter:blur(5px);height:100%;object-fit:contain;width:100%;" alt="" aria-hidden="true" onload="this.parentNode.style.opacity=1;" /></div></div></div></div>
</div>
<script>
jQuery(window).bind("load", function () {
var customvideothumbnail = document.querySelector('#customvideo div.w-css-reset:nth-of-type
@warnakey
warnakey / remove-gifs.js
Created September 3, 2021 01:17
Remove GIFs from a collection of images
/*
Let's say you have a series of images, and some are JPGs or PNGs, but some are GIFs too. If you want to remove the GIFs, you can do this.
Let's assume your HTML looked like this:
<div>
<img src="https://sqairz.com/wp-content/uploads/2021/04/freedom-white-silver-gif-600x394.gif">
<img src="https://sqairz.com/wp-content/uploads/2021/04/Sqairz-Shoes_071-600x600.jpg">
<img src="https://sqairz.com/wp-content/uploads/2021/04/freedom-white-silver-gif-600x394.gif">
</div>
*/
@warnakey
warnakey / change-woocommerce-notices.php
Created September 4, 2021 21:08
If you want to change the text of WooCommerce notices
<!-- You can add this near the bottom of your footer.php -->
<!-- As an example, assume your checkout page had these 2 notifications by default -->
<!-- and you wanted to replace both of them: https://i.snipboard.io/MvmKWL.jpg -->
<?php if($post->ID == 353034) } /* Change this ID to match the ID of your checkout page */ ?>
<script>
var getAllWooMessages = document.getElementsByClassName("woocommerce-info");
for (var i = 0; i < getAllWooMessages.length; i++) {
(function(x) {
@warnakey
warnakey / woocommerce-specific-page-function.php
Created September 4, 2021 22:54
WooCommerce Function Only Applied To A Specific Page
/* This goes in your functions.php file */
/* When the woocommerce cart is updated on the page with ID 353034, print "test" at the top of the page */
/* This is an example of using 2 functions together with an action hook */
function action_woocommerce_cart_updated() {
add_action('get_header', function() {
if (is_page('353034')) {
echo 'test';
@warnakey
warnakey / clear-woocommerce-cart-on-a-specific-page-first-time-you-visit.php
Last active September 5, 2021 00:23
Clear things from the WooCommerce cart the first time you visit a page
// This would go in your functions.php file
// Clear things out of the cart the first time you visit a specific page (only run this script once)
add_action( 'template_redirect', 'clear_cart_items_custom_checkout' );
function clear_cart_items_custom_page() {
global $post;
$slug = $post->post_name;
if($slug == 'exclusive-invitation') { // Replace this with the Slug of the page you want to clear the cart on
global $woocommerce;
$woocommerce->cart->empty_cart();
@warnakey
warnakey / review-schema-example.html
Created December 1, 2022 19:28
Review schema for legal website
<script type="application/ld+json">{
"@context": "http://schema.org/",
"@type": "Review",
"reviewBody": "They make you feel safe and taken care of. They take care of so much, they really reduce the anxiety.",
"itemReviewed": {
"@type": "LegalService",
"name": "Rose, Klein & Marias LLP",
"telephone": "(800) 362-7427",
"address": {
"@type": "PostalAddress",
@warnakey
warnakey / attorney-schema-example.html
Created December 1, 2022 19:30
Attorney schema for legal website
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Attorney",
"name": "Rose, Klein & Marias LLP",
"alternateName": " Rose, Klein & Marias",
"description": "Los Angeles personal injury attorneys",
"url" : "https://www.rkmlaw.com",
"logo" : "https://www.rkmlaw.com/wp-content/uploads/2019/11/RKMlogo.jpg",
"image" : "https://www.rkmlaw.com/wp-content/uploads/2019/11/att-riffel.jpg",
@warnakey
warnakey / legalservice-example.html
Created December 1, 2022 19:31
Legal Service schema example for lawyer website
<script type="application/ld+json">
{
"@context": "http://www.schema.org",
"@type": "LegalService",
"name": "The Dominguez Firm",
"telephone": "(800) 818-1818",
"priceRange": "$$$",
"url": "https://dominguezfirm.com",
"sameAs": [
"https://twitter.com/DominguezFirm",