Skip to content

Instantly share code, notes, and snippets.

function statusChangeCallback(response) {
fbRegister(response);
}
jQuery('.register-button').on('click', function (e) {
e.preventDefault();
ajaxRegister();
});
@guytzhak
guytzhak / float_quantities.php
Created June 8, 2020 20:39
Woocommerce Allow add to cart and calculate price based on float quantities
// Removes the WooCommerce filter, that is validating the quantity to be an int
remove_filter('woocommerce_stock_amount', 'intval');
// Add a filter, that validates the quantity to be a float
add_filter('woocommerce_stock_amount', 'floatval');
@guytzhak
guytzhak / code.php
Created June 8, 2020 20:36
Woocommerce Category add to cart btns + qantity btns for variable product
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
/* In woocommerce/single-product/add-to-cart/variable.php file use "radio button" insead of "Select" tag
* Style the radio button with their "lable" to create "Switch" UI element.
* Something like that: */
$unique_id = twentytwenty_unique_id();
$unique_id = 'product_variations_div'. ($unique_id * rand(1, 999999));
$terms = wc_get_product_terms(
@guytzhak
guytzhak / woocommerce display sub cats.php
Created June 8, 2020 20:32
Display sub cats with "active" class for the active sub category
function mz_display_sub_cats() {
$object = get_queried_object();
$current = $object->term_id;
echo '<div class="cats cats_filters d-flex flex-nowrap">';
$class = '';
if( $object->parent > 0 ) {
@guytzhak
guytzhak / ajax_add_to_cart.js
Created June 8, 2020 20:23
Woocommerce Ajax add to cart + Update the fragments needed
$('body').on('submit', '.product form', function (e) {
e.preventDefault();
var productVariationID = $(this).find('.variations').length > 0 ? $(this).find('.variation_id').val() : null,
productID = $(this).find('[name="add-to-cart"]').val(),
productQty = $(this).find('input.qty').val(),
variationArray = {},
productElm = $(this).closest('.product');
@guytzhak
guytzhak / woocommerce_update_quantities_in_cart.js
Created June 8, 2020 20:18
Woocommerce update quantities in cart
$('body').on('change keyup input', '.quantity_mini input', function () {
var qtyMiniWrapper = $(this).closest('.quantity_mini'),
qtyMiniUpdateBtn = qtyMiniWrapper.find('button.update'),
defaultQty = parseFloat(qtyMiniUpdateBtn.attr('data-default_qty')),
selectedQty = parseFloat($(this).val());
if( defaultQty !== selectedQty ) {
qtyMiniUpdateBtn.fadeIn('350');
} else {
qtyMiniUpdateBtn.fadeOut('350');
@guytzhak
guytzhak / search_results_only_products.php
Created June 8, 2020 20:13
Display only products on wordpress search results page
add_filter( 'pre_get_posts','mz_search_posts_per_page' );
// Alter search posts per page
function mz_search_posts_per_page($query) {
if ( $query->is_search ) {
$query->set( 'posts_per_page', '-1' );
$query->set( 'post_type', 'product' );
}
return $query;
}
@guytzhak
guytzhak / Woocommerce Float quantities
Last active April 1, 2020 04:21
Allow woocommerce to add to cart Float quantities
// Removes the WooCommerce filter, that is validating the quantity to be an int
remove_filter('woocommerce_stock_amount', 'intval');
// Add a filter, that validates the quantity to be a float
add_filter('woocommerce_stock_amount', 'floatval');
add_filter( 'woocommerce_quantity_input_step', 'mz_woocommerce_quantity_input_step', 99, 2 );
function mz_woocommerce_quantity_input_step($step, $product) {
// change the "step" based on $product
@guytzhak
guytzhak / auto-placeholder-images.php
Created October 17, 2019 23:38 — forked from Mosharush/auto-placeholder-images.php
This plugin resolve broken layout when we work on local machine without all uploaded images up to date. Will replace the images with image placeholder via placeholder.com
<?php
/**
* @package Auto_Placeholder_Images
* @version 1.0.0
*/
/*
Plugin Name: Auto Placeholder For Broken Images
Plugin URI: https://www.webstorm.co.il/css-live-reload/
Description: **FOR DEV USE ONLY** This plugin resolve broken layout when we work on local machine without all uploaded images up to date. Will replace the images with image placeholder via placeholder.com
Author: Moshe Harush
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
add_action('acf/init', 'ofert_acf_add_local_field_groups');
function ofert_acf_add_local_field_groups() {
//$screen = get_current_screen();