Skip to content

Instantly share code, notes, and snippets.

$( 'body' ).on( 'click', '.my_ajax_btn', function(e){
e.preventDefault();
var first_name = 'Guy';
var last_name = 'Ytzhak';
var role = 'CEO';
jQuery.ajax({
url: sp_ajaxify.ajax_url,
@guytzhak
guytzhak / ajax_func.php
Created January 2, 2018 21:24
Wordpress Ajax Call
add_action( 'wp_ajax_wordpress_ajax_action_name', 'wordpress_ajax_action_name' );
add_action( 'wp_ajax_nopriv_wordpress_ajax_action_name', 'wordpress_ajax_action_name' );
function wordpress_ajax_action_name(){
echo 'test :)';
wp_die();
}
function woocommerce_add_to_cart_variable_rc_callback() {
ob_start();
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
$quantity = empty( $_POST['quantity'] ) ? 1 : apply_filters( 'woocommerce_stock_amount', $_POST['quantity'] );
$variation_id = $_POST['variation_id'];
$variation = $_POST['variation'];
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
<?php
/*
* Save current single product to cookies
* To display those products in single product 'Recentrly searched' section
*/
add_action('wp', 'matat_save_current_single_product_to_cookies');
function matat_save_current_single_product_to_cookies() {
if( get_field('recently_viewed_cookie_num', 'options') ) {
$number_of_products = get_field('recently_viewed_cookie_num', 'options');
<?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();
@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
@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 / 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_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 / 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');