woocommerce: change default setting > is_sold_individualy function

In woocommerce/classes/abstracts/abstract-wc-product.php on line 338.
The is_sold_individualy function is default “false”.
Is there a way to set this default option to “true”? So in de WordPress back-end the checkbox is checked by default?

 function is_sold_individually() {
    $return = false;

      if ( 'yes' == $this->sold_individually || ( ! $this->backorders_allowed() && $this->get_stock_quantity() == 1 ) ) {
         $return = true;
     }

      return apply_filters( 'woocommerce_is_sold_individually', $return, $this );
  }

Thanks in advance,
Mirjam

Related posts

2 comments

  1. You can use a built-in function from WordPress:

    add_filter( 'woocommerce_is_sold_individually', '__return_true' );
    

    This line in a separate plugin will set the value always to true.

  2. You want it to be true all the time? The apply_filters() is your tip off that you can modify this value for any or all products.

    function wpa_119087_always_sold_individually( $individually, $product ){
      $individually = true;
      return $individually;
    }
    add_filter( 'woocommerce_is_sold_individually', 'wpa_119087_always_sold_individually', 10, 2 );
    

Comments are closed.