product

Rename Length to Diameter in WooCommerce formatted product dimensions output

时间秒杀一切 提交于 2019-12-23 03:21:19
问题 I’m using this woocommerce_format_dimensions filter hook to replace displayed dimensions format from 1 x 1 x 1 in to 1 L in. x 1 W in. x 1 H in. add_filter( 'woocommerce_format_dimensions', 'custom_formated_product_dimentions', 10, 2 ); function custom_formated_product_dimentions( $dimension_string, $dimensions ){ if ( empty( $dimension_string ) ) return __( 'N/A', 'woocommerce' ); $dimensions = array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ); foreach( $dimensions as

I can't fetch WooCommerce products by category id

核能气质少年 提交于 2019-12-23 02:30:51
问题 I am trying to fetch products by category ID this way: <?php $args = array( 'posts_per_page' => 20, 'taxonomy' => 'product_cat', 'post_type' => 'product', 'post_status' => 'publish', 'cat' => $cat_id ); $query = new WP_Query($args); $posts = get_posts($args); var_dump($posts); ?> The $cat_id variable contains the correct category ID. I've checked it. Products are added to correct categories. The problem is, whenever I var_dump the $posts variable I get an empty array. As soon as I remove the

Update all WooCommerce product prices to 2 decimals in database

放肆的年华 提交于 2019-12-23 02:01:44
问题 Many of my products have prices like £3.4560 etc. I need them to rounded and stripped to just 2 in the database. The output of 2 decimal places in WooCommerce is not enough and fails to work with a Tax Toggle plugin. Is there a database query that can do this? I've seen some bits on Rounding and Truncate but not sure how to execute this as my knowledge is poor. Any help is appreciated. 回答1: Update 2: (Added some code to clear all related product transient cache) Here is some code that will

Display a custom text if user has already bought the current product In Woocommerce

爷,独闯天下 提交于 2019-12-23 01:54:40
问题 In woocommerce I use wc_customer_bought_product() function to display a custom text message in single product pages when customer has already bought the current product. but I would like to check that the product(s) bought are on orders with "completed" status. The message is not supposed to be shown unless the following criteria is met: 1) user is logged in 2) user has purchased the product 3) At least one placed order for the current product is set to complete (what I cannot figure out how

Add downloads in Woocommerce downloadable product programmatically

本小妞迷上赌 提交于 2019-12-23 01:37:06
问题 I am creating a Woocommerce site where I wanna give vendors to upload products from their front end. But I stuck on a point where I am trying to add woocommerce downloadable products. Here is my current code: //Let's upload the download file Zip $zipattachment_id = upload_music_files($music_ID, $musicZip); //This is my custom function which returns attachment id after file upload $download_file_name = $musicZip['name']; $download_file_url = wp_get_attachment_url($zipattachment_id); $md5

Add a custom button for a specific product category in Woocommerce

浪尽此生 提交于 2019-12-22 18:44:15
问题 I want to display an additional button below the description to a specific product category: "bracelets" so I developed a piece of code, which does not work: add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 ); function my_extra_button_on_product_page() { if ( is_product_category('bracelets')) { global $product; echo '<a href="www.test.com">Extra Button</a>'; } } Any idea about what's wrong here? 回答1: Your question is not really clear. 1) If you want to

Product variation WP_Query with a product category in Woocommerce

試著忘記壹切 提交于 2019-12-22 18:28:42
问题 With Woocommerce, I am trying to make a WP_Query for product variations post type with a product category 'Apple'. $args = array( 'product_cat' => 'Apple', 'post_type' => array('product', 'product_variation'), 'post_status' => 'publish', 'key' => '_visibility', 'value' => 'visible', 'posts_per_page' => 100, 'taxonomy' => 'pa_size', 'meta_value' => '39', 'meta_query' => array( array( 'key' => '_stock', 'value' => 0, 'compare' => '>' ) ) ); But I can't get it work in this query. If I remove

Product variation WP_Query with a product category in Woocommerce

最后都变了- 提交于 2019-12-22 18:28:02
问题 With Woocommerce, I am trying to make a WP_Query for product variations post type with a product category 'Apple'. $args = array( 'product_cat' => 'Apple', 'post_type' => array('product', 'product_variation'), 'post_status' => 'publish', 'key' => '_visibility', 'value' => 'visible', 'posts_per_page' => 100, 'taxonomy' => 'pa_size', 'meta_value' => '39', 'meta_query' => array( array( 'key' => '_stock', 'value' => 0, 'compare' => '>' ) ) ); But I can't get it work in this query. If I remove

Remove conditionally Woocommerce cart items based on a specific product

自闭症网瘾萝莉.ら 提交于 2019-12-22 18:00:16
问题 A specific WooCommerce product can only be by itself in the cart. So how do I clear the cart while adding this specific product to the cart? and how can I remove this specific product from the cart when adding any other product? I've figured out how to empty the cart when adding a specific product but I don't know how to remove this specific product from the cart when adding any other product. 回答1: The following will remove conditionally cart items based on a specific product: When the

Disable Place Order button conditionally in Woocommerce

我是研究僧i 提交于 2019-12-22 17:58:22
问题 I have some code in a function that displays a message to the end user when the total added value of a custom field exceeds a certain value. Basically its a message telling the customer that they have ordered too much furniture to fit into a 68m3 container. I also have code which is suppose to disable the add to cart button on products - this doesn't seem to work. So is there a visible issue in the code below to disable the add to cart button when my custom field total value exceeds 68 and is