1

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

2 Answers 2

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.

0

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.