This file contains hidden or 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 | |
/* | |
* Changing the minimum quantity to 2 for all the WooCommerce products | |
*/ | |
function woocommerce_quantity_input_min_callback( $min, $product ) { | |
$min = 2; | |
return $min; | |
} |
This file contains hidden or 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 | |
function wc_qty_add_product_field() { | |
echo '<div class="options_group">'; | |
woocommerce_wp_text_input( | |
array( | |
'id' => '_wc_min_qty_product', | |
'label' => __( 'Minimum Quantity', 'woocommerce-max-quantity' ), | |
'placeholder' => '', | |
'desc_tip' => 'true', |
This file contains hidden or 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 | |
/* | |
* This function will save the value set to Minimum Quantity and Maximum Quantity options | |
* into _wc_min_qty_product and _wc_max_qty_product meta keys respectively | |
*/ | |
function wc_qty_save_product_field( $post_id ) { | |
$val_min = trim( get_post_meta( $post_id, '_wc_min_qty_product', true ) ); | |
$new_min = sanitize_text_field( $_POST['_wc_min_qty_product'] ); |
This file contains hidden or 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 | |
/* | |
* Setting minimum and maximum for quantity input args. | |
*/ | |
function wc_qty_input_args( $args, $product ) { | |
$product_id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id(); | |
$product_min = wc_get_product_min_limit( $product_id ); |
This file contains hidden or 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 | |
/* | |
* Validating the quantity on add to cart action with the quantity of the same product available in the cart. | |
*/ | |
function wc_qty_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id = '', $variations = '' ) { | |
$product_min = wc_get_product_min_limit( $product_id ); | |
$product_max = wc_get_product_max_limit( $product_id ); |
This file contains hidden or 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 | |
/* | |
* Get the total quantity of the product available in the cart. | |
*/ | |
function wc_qty_get_cart_qty( $product_id , $cart_item_key = '' ) { | |
global $woocommerce; | |
$running_qty = 0; // iniializing quantity to 0 | |
// search the cart for the product in and calculate quantity. | |
foreach($woocommerce->cart->get_cart() as $other_cart_item_keys => $values ) { |
This file contains hidden or 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 | |
/* | |
* Automatically adding the product to the cart. | |
*/ | |
function aaptc_add_product_to_cart() { | |
if ( ! is_admin() ) { | |
$product_id = 12986; // Product Id of the free product which will get added to cart | |
$found = false; |
This file contains hidden or 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 | |
/* | |
* Automatically adding the product to the cart. | |
*/ | |
function aaptc_add_product_to_cart( $item_key, $product_id ) { | |
$product_category_id = 123; // cricket bat category id |
This file contains hidden or 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 | |
/* | |
* Automatically adding the product to the cart when cart total amount reach to $500. | |
*/ | |
function aapc_add_product_to_cart() { | |
global $woocommerce; | |
$cart_total = 500; |
This file contains hidden or 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 a widget to the dashboard. | |
* | |
* This function is hooked into the 'wp_dashboard_setup' action below. | |
*/ | |
function wc_orders_dashboard_widgets() { | |
wp_add_dashboard_widget( | |
'wc_order_widget_id', // Widget slug. |
OlderNewer