Building a plugin for custom atalog mode, ideas?
-
We have an online woocommerce store aside from our physical store. My problem is that some products should not be available to buy online, they should only be available through our physical store. I still want to show them online however, and also show stock status along with variable prices.
I’ve seen a lot of “catalog mode” plugins out there, however none of them does the job I am looking for. Basically here’s what I want to do:
Have an option under general to disable add to cart button and quantity.
When checked, the add to cart button will be removed from site on both archive pages and single product pages, including the quantity option. It will also add some information text instead, something like “This product is not available online, please contact us if you want to buy this item.”
I have many different solutions, but it’s the code I have problems with 😉
Here’s what I have today:
// Add checkbox in admin add_action( 'woocommerce_product_options_general_product_data', 'woo_single_product_catalog_mode' ); function woo_single_product_catalog_mode() { global $woocommerce, $post; echo '<div class="options_group">'; woocommerce_wp_checkbox( array( 'id' => 'custom_remove_add_to_cart', 'wrapper_class' => 'checkbox_class', 'label' => 'Disable add to cart', 'description' => 'Enable to remove quantity/add to cart and show a message instead' ) ); echo '</div>'; } // Save fields add_action( 'woocommerce_process_product_meta', 'woo_single_product_catalog_mode_save' ); function woo_single_product_catalog_mode_save( $post_id ){ $woo_checkbox = $_POST['custom_remove_add_to_cart']; if( !empty( $woo_checkbox ) ) { update_post_meta( $post_id, 'custom_remove_add_to_cart', 'yes' ); } else { delete_post_meta( $post_id, 'custom_remove_add_to_cart' ); } }All this code does is to add the option as shown in image, when checked it will add a custom field ‘custom_remove_add_to_cart’ with the value ‘yes’ and if unchecked it will remove that custom field. Next up is to add some functions if a product i checked.
Since there doesn’t seem to be a way (at least not that I’ve found) to remove the add to cart button, we could add a class to the product post instead, and then by css simply hide it:
.woocommerce .catalog-mode form.cart button.button, .woocommerce .catalog-mode form.cart div.quantity {display: none !important;}My trouble here is I don’t know how to create a function to add a class to the post if custom field value ‘custom_remove_add_to_cart’ is ‘yes’
Next up I want to add some text instead of the add to cart button. I have some code ready, but again, I only want it to show if custom field value ‘custom_remove_add_to_cart’ is ‘yes’.
// Add text instead add_filter('woocommerce_before_add_to_cart_button','woo_single_product_catalog_mode_front_text'); function woo_single_product_catalog_mode_front_text($catalog_text) { if ( is_woocommerce()){ ?> <div class="catalog-text"> <p>This product is not available online, please contact us if you want to buy this item.</p> </div> <?php return $catalog_text; } else { return $catalog_text; } }I now it’s kinda complex to explain what I am trying to do here and I don’t know if this is the right forum to ask, so please tell me if I should ask for help anywhere else 😉
The topic ‘Building a plugin for custom atalog mode, ideas?’ is closed to new replies.