product

Get the count of all “In stock” products in WooCommerce

百般思念 提交于 2019-12-11 07:32:44
问题 I have a site where products are considered trade/deal. Therefore, when someone take a trade (buy a product), it become out of stock. What would be the PHP snippet to display the remaining numbers of product currently available (basically In Stock) ? ex: Hurry Up! Only 10 trades (woocommerce -> products) available! Thanks in advance! I tried the code provided : function fp2() { global $wpdb; $stock = get_post_meta( $post->ID, '_stock', true ); echo '<span style="color:#fff;text-align:center

Custom checkbox in product settings that displays a custom field when checked

落花浮王杯 提交于 2019-12-11 07:29:14
问题 I am currently working on a WordPress eCommerce website, using WooCommerce. I have created a custom Checkbox within the Product edit pages general settings. I have also a code snippet that is displaying a custom text field in single product pages. Now I would like when this custom Checkbox is checked for a product (in it's settings), to display this custom text field in single product pages. The Coding I have so far: To create the Checkbox, within the WooCommerce Product Dashboard, I have

Hiding tabs only for some products in WooCommerce single product pages

☆樱花仙子☆ 提交于 2019-12-11 07:24:58
问题 I would like to know how can I hide or remove the WooCommerce tabs only on certain single product pages (keeping them on other pages using css or jquery if that's possible)? Woocommerce div tabs: class="woocommerce-tabs wc-tabs-wrapper" 回答1: It's very easy to remove the WooCommerce tabs on certain single products. You can easily do this using CSS. Every WC products have a Unique product id, please check this http://prntscr.com/dp2c79 , you will find this using Browser inspect element or

Display custom stock quantity conditionally via shortcode on Woocommerce

安稳与你 提交于 2019-12-11 07:19:35
问题 I'm using WooCommerce: Display stock quantity for a given product ID on normal Pages or Posts amazing answer code that works to display the product quantity for a WooCommerce product in any page or post via a shortcode. I would like to only display the exact quantity up to 5 products in stock and have "More than 5" for any quantity of 6 or more. Can it be done by modifying this code? 回答1: The following should do the trick: if( !function_exists('show_specific_product_quantity') ) { function

How to set a non existing dimensions measurement unit in Woocommerce 3

允我心安 提交于 2019-12-11 07:02:20
问题 In WooCommerce I would like to change cm to ft my products display in height, width and length, You can see the products with their title below: 回答1: Try the following code that will change the displayed dimensions unit in front end: add_filter( 'woocommerce_format_dimensions', 'custom_dimention_unit', 20, 2 ); function custom_dimention_unit( $dimension_string, $dimensions ){ $dimension_string = implode( ' x ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) ); if ( !

Add sorting by modified date in Woocommerce products sort by

独自空忆成欢 提交于 2019-12-11 06:54:52
问题 In woocommerce, I would like to add the possibility to sort the products by "Modified date" in shop and archives pages. How can I add "Sort By date modified " in woocommerce product sorting dropdown? Any help is appreciated. 回答1: This can be done very easily with the following code, which will add a sorting by modified date: add_filter( 'woocommerce_get_catalog_ordering_args', 'enable_catalog_ordering_by_modified_date' ); function enable_catalog_ordering_by_modified_date( $args ) { if ( isset

WooCommerce: Add a product attribute to the existing ones in a product

醉酒当歌 提交于 2019-12-11 06:45:34
问题 I am struggling with adding an attribute to a product. I have an array of keywords that I would like to add to a product: $clean_keywords = array('cake','cup cakes'); $term_taxonomy_ids = wp_set_object_terms( get_the_ID(), $clean_keywords, 'pa_keywords', true ); $thedata = Array('pa_keywords' => Array( 'name' => 'pa_keywords', 'value' => '', 'is_visible' => '0', 'is_taxonomy' => '1' )); update_post_meta( get_the_ID(),'_product_attributes',$thedata); This works fine, but it deletes all my

Adding programatically more downloadable files for products in WooCommerce

人盡茶涼 提交于 2019-12-11 06:17:36
问题 I am trying to uploaded one more downloadable files in woocommerce product. I have already one downloadable file in my product and want to add one more. For this I am using following code: if($_FILES){ $attachment_id = media_handle_upload( 'abe_update_epub', $post_id ); if ( is_wp_error( $attachment_id ) ) { $errors = $attachment_id->get_error_messages(); foreach( $errors as $error ){ echo $error; } echo 'There was an error uploading the image'; } else { // to get exiting file/Old file $abe

For specific products on WooCommerce orders with completed status, perform an action

十年热恋 提交于 2019-12-11 06:14:15
问题 IN WooCommerce, I would like to perform an action if at least one product from a list is bought and if the current order status for that product is completed. For instance I can only verify if the product is bought: global $woocommerce; $user_id = get_current_user_id(); $current_user= wp_get_current_user(); $product_list = array('11', '12', '13', '14', '15','16'); $text= false; foreach ($product_list as $value): if (wc_customer_bought_product( $customer_email, $user_id, $value) ) { $text =

Customizing product variations message on single product pages

血红的双手。 提交于 2019-12-11 06:09:57
问题 I got a WooCommerce website, which hides the prices for not logged in users, and apparently it works fine, except with product variations, that even if it does what it should, is not properly done, or at least not the way I would do it. I hides the price of the variable product, but allows you to choose options (which is fine, that way you might encourage users to register) the problem is that when you finish choosing the variables, it shows the following message "Sorry, this product is