This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
/** | |
* Const to declare number of posts to show per page in the table. | |
*/ | |
const POSTS_PER_PAGE = 10; | |
/** | |
* Property to store post types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( 'MAX_QUANTITY', 3 ); | |
add_filter( | |
'woocommerce_add_to_cart_validation', | |
'validate_discounted_prdct_qty_limitation', | |
10, | |
3 | |
); | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 }); |