Skip to content

Instantly share code, notes, and snippets.

@morvy
morvy / functions.php
Created June 30, 2023 17:58
Fix add_to_cart event not firing on Woo Product where theme uses custom ajax event
<?php
/**
* GA4 event: add_to_cart
*/
add_action('wp_footer', function() {
if (!is_product()) return;
?>
<script type="text/javascript">
// track add to cart events for products on product detail pages
jQuery(document).ready(function($) {
@morvy
morvy / shortcodes.php
Last active June 11, 2023 16:00
Converts [some] WP Bakery shortcodes into Gutenberg blocks
<?php
// load wp
require_once( dirname( __FILE__ ) . '/wp-load.php' );
// get post content by ID
if (empty($_GET['id'])) {
die('ID is empty');
}
$id = $_GET['id'];
$post = get_post( $id );
@morvy
morvy / functions.php
Created December 26, 2021 19:01
[PWB slider for Flatsome] Brands slider for Perfect WooCommerce Brands + Flatsome #flatsome #woocommerce #brands
<?php
/**
* @author Peter Morvay <moped@jepan.sk>
* @package Flatsome
* @version 3.14.3
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
@morvy
morvy / functions.php
Created September 20, 2020 09:50
Blocksy Latest Posts - cards shortcode
<?php
function pmo_home_blog() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$args = array(
'showposts' => 3,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
@morvy
morvy / functions.php
Created March 30, 2020 16:46
[WPR exclude defer] Exclude scripts from WP Rocket’s defer JS option. #wordpress #wprocket
/**
* Exclude scripts from WP Rocket’s defer JS option.
*
* @author Caspar Hübinger
* @param array $excluded_files Array of script URLs to be excluded
* @return array Extended array script URLs to be excluded
*/
function exclude_files( $excluded_files = array() ) {
/**
@morvy
morvy / install.php
Last active February 12, 2024 09:20 — forked from tschoffelen/install.php
[WP installer] A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually. #wordpress #installer
<?php
echo '<span style="color:green">Extracting WordPress...</span>' . PHP_EOL;
// Download the latest WordPress ZIP file
download_wordpress_zip();
// Extract and move WordPress files
if (extract_and_move_files()) {
// Remove 'wordpress' folder and installer
remove_directory("wordpress");
@morvy
morvy / functions.php
Created January 7, 2020 18:46
Function override of flatsome_wc_get_gallery_image_html
<?php
/**
* Function override for Flatsome theme
* - disables main image link on product page
*
* @param integer $attachment_id
* @param bool $main_image
* @param string $size
* @return string
*/
@morvy
morvy / functions.php
Created December 1, 2019 21:12
[Debug WP updates] Debug WordPress aktualizácií #wordpress
/**
* Debug WP updates
* Displays hidden plugin and theme updates on update-core screen.
*
* @source https://stackoverflow.com/questions/22137814/wordpress-shows-i-have-1-plugin-update-when-all-plugins-are-already-updated/52132227
* @author Peter Morvay <moped@jepan.sk>
*/
function debug_pending_updates() {
// Rough safety nets
/**
* Blocks order if condition is met
* - blocks Emma Rose orders
* - blocks orders from New York
*
* @param array $data
* @param object $errors
* @return void
*/
function pmo_custom_checkout_field_validation( $data, $errors ) {
@morvy
morvy / index.php
Last active April 7, 2019 10:29
Laragon.org enhanced "homepage"
<?php
if (!empty($_GET['q'])) {
switch ($_GET['q']) {
case 'info':
phpinfo();
exit;
break;
}
}
?>