I think this code can be more efficiently written as:
$product_status = $product->get_status();
get_post_status( $product_id ) will force ClassicCommerce to find the WP_Post object in the cache whereas $product->get_status() just dereferences an existing object.
This is not a quibble for me as the products of my plugin are virtual (i.e., they do not exists in the database) and the WP_Post objects are not naturally created. Of course, I can artificially create them but this really should not be necessary. When a ClassicCommerce WC_Product object is constructed a WP_Post object is also constructed and the fields in the WP_Post object are copied to fields in the WC_Product object so the WP_Post object is really not needed anymore. Of course the WP_Post object continues to live in the cache so using it is not very expensive. However, in my case it does not naturally exists in the cache. Currently, I artificially create it and insert into the cache but I would rather remove that code.
Moreover, as I commented in an earlier issue I think $product_status is misused and the behavior of WC_AJAX::add_to_cart() is incorrect. However, I can understand the reluctance to change the behavior of code that has seemingly worked correctly for several years. The change I propose here should not change the behavior of WC_AJAX::add_to_cart() except for running slightly faster but will allow my plugin to work better.
https://github.com/ClassicPress-plugins/classic-commerce/blob/10650f8347d4307b8b02ccdc76195e544cb50e51/includes/class-wc-ajax.php#L381
I think this code can be more efficiently written as:
$product_status = $product->get_status();
get_post_status( $product_id ) will force ClassicCommerce to find the WP_Post object in the cache whereas $product->get_status() just dereferences an existing object.
This is not a quibble for me as the products of my plugin are virtual (i.e., they do not exists in the database) and the WP_Post objects are not naturally created. Of course, I can artificially create them but this really should not be necessary. When a ClassicCommerce WC_Product object is constructed a WP_Post object is also constructed and the fields in the WP_Post object are copied to fields in the WC_Product object so the WP_Post object is really not needed anymore. Of course the WP_Post object continues to live in the cache so using it is not very expensive. However, in my case it does not naturally exists in the cache. Currently, I artificially create it and insert into the cache but I would rather remove that code.
Moreover, as I commented in an earlier issue I think $product_status is misused and the behavior of WC_AJAX::add_to_cart() is incorrect. However, I can understand the reluctance to change the behavior of code that has seemingly worked correctly for several years. The change I propose here should not change the behavior of WC_AJAX::add_to_cart() except for running slightly faster but will allow my plugin to work better.