H
H
hypero2020-02-25 20:27:35
PHP
hypero, 2020-02-25 20:27:35

Changing the quantity of a Woocommerce item?

Hello.

There is code in functions.php:

if(get_field('wholesale', $post->ID)) {
  add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
  function jk_woocommerce_quantity_input_args( $args, $product ) {
    if ( is_singular( 'product' ) ) {
      $args['input_value'] 	= 5;	// Starting value (we only want to affect product pages, not cart)
    }
    $args['max_value'] 	= 100; 	// Maximum value
    $args['min_value'] 	= 5;   	// Minimum value
    $args['step'] 		= 1;    // Quantity steps
    return $args;
  }
  // Variations
  add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );
  function jk_woocommerce_available_variation( $args ) {
    $args['max_qty'] = 100; 		// Maximum value (variations)
    $args['min_qty'] = 5;   	// Minimum value (variations)
    return $args;
  }
}


There is ACF Yes/No field on Woocommerce product page.
If there is a checkmark, then the code should work.
Now does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2019-07-04
@IwanQ

There is. Use cURL .
upd. In fact, very few sites now can simply give away page content without context. At a minimum, they need all sorts of cookies, user agents, and so on. Theoretically, it is possible to pass the request context to file_get_content , but cURL handles this better and easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question