Skip to content

Instantly share code, notes, and snippets.

View gvgvgvijayan's full-sized avatar

Vijayan gvgvgvijayan

View GitHub Profile
<?php
...
/**
* Const to declare number of posts to show per page in the table.
*/
const POSTS_PER_PAGE = 10;
/**
* Property to store post types
<?php
...
/**
* Class Drafts_List_Table.
*
* @since 0.1.0
* @package Admin_Table_Tut
* @see WP_List_Table
*/
class Drafts_List_Table extends \WP_List_Table {
<?php
/**
* Plugin Name: Admin Table Tutorial
* Plugin URI: www.vijayan.in
* Description: This plugin is created for the purpose to understand the WordPress admin table.
* Author: Vijayan
* Author URI: www.vijayan.in
* Text Domain: admin-table-tut
* Domain Path: /languages
* Version: 0.1.0
<?php
/**
* Helper function to check discounted product add to cart limit reached.
*
* @param int $product_id Product ID.
* @param int $quantity Product quantity.
* @param string $action_type Type of the action. Allowed 'add' or 'update'.
*
* @return bool Return true if quantity exceeded else false.
*/
<?php
/**
* Validation function to limit the quantity.
*
* @param int $product_id Product ID.
* @param int $quantity Product quantity.
* @param string $action_type Type of the action. Allowed 'add' or 'update'.
*
* @return bool Return true if quantity is not exceeded else false.
<?php
add_filter(
'woocommerce_update_cart_validation',
'on_update_cart_limit_qty',
10,
4
);
/**
* Hooked functionality to check limit of the discounted product quantity in cart page on updating the cart.
<?php
define( 'MAX_QUANTITY', 3 );
add_filter(
'woocommerce_add_to_cart_validation',
'validate_discounted_prdct_qty_limitation',
10,
3
);
/**
<?php
add_action('wp_footer', 'update_quantity_attribute');
function update_quantity_attribute()
{
?>
<script type='text/javascript'>
let simpleProductInput = document.querySelectorAll('.product-type-simple .quantity > input');
simpleProductInput.forEach(dom => {
dom.addEventListener('input', e => {
add_filter('woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2);
function quantity_inputs_for_woocommerce_loop_add_to_cart_link($html, $product)
{
if ($product && $product->is_type('simple') && $product->is_purchasable() && $product->is_in_stock() && !$product->is_sold_individually()) {
woocommerce_quantity_input(array(), $product);
}
return $html;
}
//https://stackoverflow.com/a/43792563
// Store a copy of the fetch function
var _oldFetch = fetch;
// Create our new version of the fetch function
window.fetch = function () {
// Create hooks
var fetchStart = new Event('fetchStart', { 'view': document, 'bubbles': true, 'cancelable': false });
var fetchEnd = new Event('fetchEnd', { 'view': document, 'bubbles': true, 'cancelable': false });