Skip to content

Instantly share code, notes, and snippets.

@hmouhtar
hmouhtar / script.js
Created June 28, 2024 21:43
Elementor - Show Popup Programmatically / Disable other popups
window.addEventListener('elementor/frontend/init', function() {
var popupId = 13473;
function getReferrer() {
return document.referrer;
}
function isBot() {
var botList = ["Googlebot", "Bingbot", "Slurp", "DuckDuckBot", "Baiduspider", "YandexBot"];
var userAgent = navigator.userAgent.toLowerCase();
@hmouhtar
hmouhtar / functions.php
Created May 19, 2024 19:53
Elementor - Replace nav menu programatically based on MemberPress membership
<?php
add_action( 'elementor/frontend/widget/before_render', function( $widget ) {
// Ensure the widget is the Nav Menu widget
if ( 'nav-menu' === $widget->get_name() ) {
// Get the widget settings
$widgetSettings = $widget->get_settings_for_display();
$widgetId = $widgetSettings['_element_id'];
// Check if the widget ID is headerNavMenu
@hmouhtar
hmouhtar / functions.php
Last active June 12, 2024 19:17
Elementor - Make Nav Menu Toggle Animated
This snippet filters the content of the Elementor Nav Menu Widget to
add the required markup for the animated toggle (3 spans).
function replaceMenuToggleContent($html) {
// Wrap the HTML with a root element to prevent unexpected restructuring
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML('<div>' . $html . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
@hmouhtar
hmouhtar / gflow_redirect.php
Created June 3, 2022 16:51
Gravity Flow - Redirect based on current user step.
/*
The Collective Rising relies on Gravity Flow to automate the membership workflow. After a member applies, an admin from TCR
accepts/rejects the application. Accepted members must complete a form with information that will be used to create their profile
in the website, and they should be redirected to that form if they haven't finished it yet and try to navigate to their profile.
This code snippet, although short, required a lot of research on the methods Gravity Flow used to gather information of the user progress
in the workflow.
*/
function redirect_to_profile_builder() {
@hmouhtar
hmouhtar / price-quantity.php
Last active July 12, 2021 10:27
Link price to quantity - WooCommerce for Elementor
add_action( 'woocommerce_before_add_to_cart_quantity', function(){
global $woocommerce, $product;
if ( $product->is_type( 'variable' ) ) {
?>
<script>
jQuery(function ($) {
$(document).ready(function () {
var price,
currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
@hmouhtar
hmouhtar / gulpfile.js
Last active February 3, 2019 14:29
A gulpfile to compile SASS, add necessary prefixes and minify the resulting css file. Also includes a function to compress images.
// Gulp components
const {
series,
src,
dest,
watch
} = require('gulp');
// Dependencies