Skip to content

Instantly share code, notes, and snippets.

View softiconic's full-sized avatar

Softiconic softiconic

View GitHub Profile
@softiconic
softiconic / functions.php
Last active December 2, 2023 19:01
Develop a new widget using the theme function with the Elementor page builder plugin.
//Elementor Function Code
class ElementorCustomElement
{
private static $instance = null;
public static function get_instance()
{
if (!self::$instance)
self::$instance = new self;
return self::$instance;
}
@softiconic
softiconic / functions.php
Last active December 2, 2023 19:01
Exclude a shipping method on the WooCommerce cart page.
/**
* remove shipping method - Cart page
* Put this in your functions.php file
*/
function disable_shipping_calc_on_cart( $show_shipping ) {
if( is_cart() ) {
return false;
}
return $show_shipping;
}
@softiconic
softiconic / functions.php
Last active December 2, 2023 19:00
Alter the currency display in WooCommerce.
/**
* Change currency display in WooCommerce
* Put this in your functions.php file
*/
function softiconic_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'USD':
$currency_symbol = 'USD $';
break;
case 'CAD':
@softiconic
softiconic / functions.php
Last active December 2, 2023 19:00
Replace a class in the submenu of a WordPress navigation menu.
/**
* Put this in your functions.php file
*/
function change_submenu_class($menu) {
$menu = preg_replace('/ class="sub-menu"/','/ class="sc-dropdown" /',$menu);
return $menu;
}
add_filter('wp_nav_menu','change_submenu_class');
@softiconic
softiconic / gist:6b4be169c0e795dc1f29bf809ba2d9f3
Last active December 2, 2023 18:59
In a WooCommerce product page, implement AJAX for the "Add to Cart" functionality.
//Remove old button which submiting form:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
//Add ajax-link from archive page to single product page:
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_loop_add_to_cart', 30 );
@softiconic
softiconic / functions.php
Last active December 2, 2023 18:59
Show the weight and a message indicating the remaining weight on the WooCommerce cart and checkout.
add_filter( 'woocommerce_before_cart', 'display_total_weight_notice' );
add_filter( 'woocommerce_before_checkout_form', 'display_total_weight_notice' );
function display_total_weight_notice( $message ) {
// DEFINE the allowed weight limit
$allowed_weight = 3;
$cart_total_weight = WC()->cart->get_cart_contents_weight();
if( cart_total_weight <= $allowed_weight ) :
wc_print_notice( sprintf(
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:58
Convert an image source (img src) into a background image using a combination of script and CSS.
//Replace carousel images into background images.
$('#carousel .item img').each(function() {
var imgSrc = $(this).attr('src');
$(this).parent().css({'background-image': 'url('+imgSrc+')'});
$(this).remove();
});
@softiconic
softiconic / custom.js
Last active October 29, 2024 04:31
JavaScript for scrolling through pages or sections.
$(document).ready(function() {
// Define the offset
var offset = -200; // Adjust this value as needed
// Function to scroll to the target with offset
function scrollToTarget(target) {
$('html, body').animate({
scrollTop: target.offset().top + offset
}, 1000);
}
@softiconic
softiconic / gist:5b0e31a5cd36b61e5a8475797f8b0358
Last active December 2, 2023 18:58
Fixed header that remains sticky as you scroll.
//**********Sticky Header**********
$(window).on('scroll', function (){
var sticky = $('header'),
scroll = $(window).scrollTop();
if (scroll >= 100) sticky.addClass('sticky');
else sticky.removeClass('sticky');
});
@softiconic
softiconic / gist:eb43d0e17cdc17645351422a344384be
Last active December 2, 2023 18:57
Script for a navigation menu.
$('.dropdown-menu a.dropdown-toggle').on('click', function(e) {
if (!$(this).next().hasClass('show')) {
$(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
}
var $subMenu = $(this).next(".dropdown-menu");
$subMenu.toggleClass('show');
$(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) {
$('.dropdown-submenu .show').removeClass("show");
});