Skip to content

Instantly share code, notes, and snippets.

View zackeryfretty's full-sized avatar

Zackery Fretty zackeryfretty

View GitHub Profile
// Integrate WPF Return into Gravity Forms Login Shortcode
function zf_check_for_wpf_return_cookie_on_login( $login_redirect, $sign_on ) {
// Check for WPF Return Cookie and ensure it's a valid post ID
if ( isset( $_COOKIE["wpf_return_to"] ) && is_numeric( $_COOKIE["wpf_return_to"] ) ) {
// Get Permalink for the specified post ID
$return_url = get_permalink( (int) $_COOKIE["wpf_return_to"] );
// Set Redirect to the sanitized URL
jQuery('.uabb-offcanvas-menu .uabb-has-submenu').on('click', function() {
event.stopPropagation();
var $clickedItem = jQuery(this);
var $clickedItemSub = jQuery(this).find('.sub-menu');
var $allItems = jQuery('.uabb-offcanvas-menu .uabb-has-submenu');
var $allSubs = jQuery('.uabb-offcanvas-menu .uabb-has-submenu .sub-menu');
$allSubs.not($clickedItemSub).slideUp();
@zackeryfretty
zackeryfretty / SHOPIFY: Hide ReBuy Widget if Subscription in Cart.js
Created April 15, 2025 15:55
Replace 'widget.id' with your actual widget id.
// Hide Free Cases if Subscription in Cart
function hideWidgetIfSubscription() {
let subscription_exists = false;
const rebuy_widget = window.Rebuy.widgets.find(widget => widget.id === "161420");
const cart_items = Rebuy.SmartCart.items();
// Use some to check for subscription existence
subscription_exists = cart_items.some(item => item.product.subscription === true);
// Get Active Tabs Object
const getActiveTabs = () => {
const tabObject = {}; // Initialize an empty object
const wooTabsContainer = document.querySelector('.wc-tabs-wrapper');
// Check if the container exists
if (!wooTabsContainer) {
console.error('Tabs container not found.');
return tabObject; // Return an empty object if not found
@zackeryfretty
zackeryfretty / Disable WooCommerce Checkout API & Record Attempts
Last active December 18, 2024 18:56
Redirects any traffic to the WooCommerce '/wc/store/checkout' endpoint back to the homepage and logs the attempt in the error_log for review.
<?php
function zf_block_and_log_checkout_api_requests() {
$current_url = $_SERVER['REQUEST_URI'];
$msg_to_log = 'Checkout API Blocked: ' . $_SERVER['REMOTE_ADDR'];
if ( strpos( $current_url, '/wp-json/wc/store/checkout' ) !== false ) {
error_log( $msg_to_log , 0);
wp_redirect( home_url() );
exit;
@zackeryfretty
zackeryfretty / WooCommerce: Get Returned Count from Line Item in Order
Last active November 8, 2024 19:07
When looping through the items in an order pass the $item to this function to get the quantity returned from the line item.
function zf_get_line_item_returned_quantity( $item, $order ) {
$returned_quantity = 0;
foreach ($order->get_refunds() as $refund) {
foreach ($refund->get_items() as $refund_item) {
if ($refund_item->get_product_id() == $item->get_product_id()) {
$returned_quantity += $refund_item->get_quantity();
}
}
@zackeryfretty
zackeryfretty / WP All Export: Include Products With WooCommerce Subscriptions
Created June 14, 2024 21:04
Passing the "Subscription ID" to this function when exporting WooCommerce Subscriptions via WP All Export will build a comma separated list of the items the subscription (which isn't included by default).
function zf_get_recent_subscription_order_items( $id ){
if ( is_nan( $id ) ) {
return '';
}
$subscription = new WC_Subscription( $id );
$related_orders = $subscription->get_related_orders();
$recent_order_id = current( $related_orders );
$recent_order = wc_get_order( $recent_order_id );
// ACF: Options Page Field Getter
function zf_acf_options_field_shortcode( $atts ){
$atts = shortcode_atts(
array(
'field' => '',
),
$atts,
'zf-acf-options-field'
);
// Grab Testimonial Row 1 Output
function zf_get_testimonial_row_one_posts($settings, $query){
// Only Testimonial Row 1
if($settings->id == 'zf-praise-row-module-1') {
// Define Global Array
$GLOBALS['praise_to_exclude'] = [];
// Grab Testimonal Row 1 Posts
@zackeryfretty
zackeryfretty / Rename Passed Values in Zapier.js
Created February 15, 2024 04:06
For use with "Code" step, using JavaScript, useful for renaming values that come across from triggers.
/*
For use with "Code" step, using JavaScript,
useful for renaming values that come across from triggers.
inputData is the Object Zapier creates for the passed values.
*/
// Translation Table for Looking up
const translationTable = {
// "Source" : "Translation"
"fog-score{1}" : "Rarely",