Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_quantity_input_args', function ( $args, $product ) {
- $min_order_qty = wcfm_get_post_meta( $product->get_id(), 'wcfm_min_order_qty', true );
- $args['min_value'] = $min_order_qty ? $min_order_qty : 1;
- $order_qty_step = wcfm_get_post_meta( $product->get_id(), 'wcfm_order_qty_step', true );
- $args['step'] = $order_qty_step ? $order_qty_step : 1;
- return $args;
- }, 1, 2 );
- add_filter('wcfm_product_fields_stock', function($fields, $product_id) {
- $index = array_search( "sku", array_keys( $fields ) ) + 1;
- if ( $index !== false ) {
- $min_order_qty_field = array( "wcfm_min_order_qty" => array(
- 'label' => __( 'Minimum order quantity', 'wc-frontend-manager' ),
- 'type' => 'number',
- 'class' => 'wcfm-text wcfm_non_negative_input',
- 'label_class' => 'wcfm_title',
- 'value' => wcfm_get_post_meta( $product_id, 'wcfm_min_order_qty', true ),
- 'placeholder' => 'Keep it blank for minimum quantity as 1',
- ),
- );
- $qty_step_field = array( "wcfm_order_qty_step" => array(
- 'label' => __( 'Order quantity step size', 'wc-frontend-manager' ),
- 'type' => 'number',
- 'class' => 'wcfm-text wcfm_non_negative_input',
- 'label_class' => 'wcfm_title',
- 'value' => wcfm_get_post_meta( $product_id, 'wcfm_order_qty_step', true ),
- 'placeholder' => 'Keep it blank for default step value 1',
- ),
- );
- return array_slice( $fields, 0, $index, true ) +
- $min_order_qty_field + $qty_step_field +
- array_slice( $fields, $index, count( $fields ) - 1, true );
- }
- return $fields;
- }, 10, 2);
- add_action( 'after_wcfm_products_manage_meta_save', function($new_product_id, $wcfm_products_manage_form_data) {
- $min_order_qty = 1;
- if ( !empty( (int) $wcfm_products_manage_form_data[ 'wcfm_min_order_qty' ] ) ) {
- $min_order_qty = (int) $wcfm_products_manage_form_data[ 'wcfm_min_order_qty' ];
- }
- wcfm_update_post_meta( $new_product_id, 'wcfm_min_order_qty', $min_order_qty );
- $order_qty_step = 1;
- if ( !empty( (int) $wcfm_products_manage_form_data[ 'wcfm_order_qty_step' ] ) ) {
- $order_qty_step = (int) $wcfm_products_manage_form_data[ 'wcfm_order_qty_step' ];
- }
- wcfm_update_post_meta( $new_product_id, 'wcfm_order_qty_step', $order_qty_step );
- }, 91, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement