admin管理员组

文章数量:1122846

I have wordpress setup with woocommerce.

Now I have set the option Sold individually to yes check the screenshot

But when I click on the add to cart button of that product and check the value again in admin it got unchecked.

I have even updated the woocommerce but same.

After doing a bit more debug I found that the below code is responsible for changing the value

private static function add_to_cart_handler_simple( $product_id ) {
        $quantity          = empty( $_REQUEST['quantity'] ) ? 1 : wc_stock_amount( wp_unslash( $_REQUEST['quantity'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
        die("aa");
        $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );

        if ( $passed_validation && false !== WC()->cart->add_to_cart( $product_id, $quantity ) ) {
            wc_add_to_cart_message( array( $product_id => $quantity ), true );
            return true;
        }
        return false;
    }

Specially this section

$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );

As you can see that I have added die("aa"); in the code that prevent value to change but if I place this code after $passed_validation line the value has changed.

本文标签: pluginssoldindividually value change when add to cart