Posts

Showing posts with the label Coding Style

Add A Custom Stock Status In WooCommerce

Answer : for anyone interested, here is complete solution, based on Laila's approach. Warning! My solution is intended to work only with WooCommerce "manage stock" option disabled ! I am not working with exact amounts of items in stock. All code goes to functions.php , as usual. Back-end part Removing native stock status dropdown field. Adding CSS class to distinguish my new custom field. Dropdown has now new option "On Request". function add_custom_stock_type() { ?> <script type="text/javascript"> jQuery(function(){ jQuery('._stock_status_field').not('.custom-stock-status').remove(); }); </script> <?php woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array( '...

Alphabetizing Methods In Visual Studio

Answer : While Resharper has many cool features it has a large impact in CPU and I/O usage and can be very complicated to use. It is also only available under commercial licensing unless you qualify for a few very specific free use licenses. Try CodeMaid. It is free for commercial use and has a much lower performance overhead. I find it easy to use and it is very good for alphabetizing methods. To sort your file, open the file via solution explorer: Right click the open file Code Maid menu (likely near the top of the right click menu) Click Reorganize Active Document Alternatively, using the default CodeMaid hotkeys CTRL + M , Z to sort your active file. Resharper has a Type Members Layout, which can order members by type, accessibility and alphabetically as well. You can also take a look into Ora , which presents a pane in visual studio that is ordered (even though your source may not be). Link's dead. The following answer goes much further than the OP asks,...

Advantages Of Using Arrays Instead Of Std::vector?

Answer : In general, I strongly prefer using a vector over an array for non-trivial work; however, there are some advantages of arrays: Arrays are slightly more compact: the size is implicit. Arrays are non-resizable; sometimes this is desirable. Arrays don't require parsing extra STL headers (compile time). It can be easier to interact with straight-C code with an array (e.g. if C is allocating and C++ is using). Fixed-size arrays can be embedded directly into a struct or object, which can improve memory locality and reducing the number of heap allocations needed. Because C++03 has no vector literals. Using arrays can sometime produce more succinct code. Compared to array initialization: char arr[4] = {'A', 'B', 'C', 'D'}; vector initialization can look somewhat verbose std::vector<char> v; v.push_back('A'); v.push_back('B'); ... I'd go for std::array available in C++0x instead of plain arrays which can...