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 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 / 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 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 / 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: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: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;
}