product

Conditional product prices cart issue in WooCommerce 3

蓝咒 提交于 2019-12-02 05:24:48
问题 I modified a function to create custom prices for some of my members i.e. the normal price is $1 but if you're a bronze member it's $2, a silver member $3, etc. The prices are changed on the shop and single product page. When the product is added to the cart, however, the price reverts to the original amount. Is there additional code I should be including to have the price accurately changed all the way through checkout and billing? // Variations (of a variable product) add_filter(

Sort a Woocommerce product variations custom output by their price

蹲街弑〆低调 提交于 2019-12-02 05:00:59
问题 Bellow I have a custom shortcode function based on this answer code that displays a block of product data for both Simple products and each variation of a Variable product. The output of the variation blocks seems to be ordered by the ID of the variation itself. For example, this is a screenshot of the frontend output: Which you can see matches the order of the variation IDs (from smallest to largest) screenshot: What I would like is to sort the variations by their prices instead (NOT by

Adding custom settings tab for simple products in Woocommerce

為{幸葍}努か 提交于 2019-12-02 04:02:13
I am having a problem trying to add a custom field called Discount_info to a simple product. I have created a new tab called discount_info which shows up in the simple product view just fine. Problem is trying to add a custom number field to this tab. I'm using the code below which is causing a 500 error. Any ideas where i am going wrong? // Display Fields using WooCommerce Action Hook add_action( 'woocommerce_product_options_discount_info', 'woocom_general_product_data_custom_field' ); function woocom_general_product_data_custom_field() { // Create a custom text field // Number Field

Automatically assign products to a defined product category in WooCommerce

徘徊边缘 提交于 2019-12-02 04:00:08
问题 In Woocommerce, I am trying to automatically assign a given product category to products if they have a specific custom field value (Using Advanced custom fields plugin to generate this field). In my functions.php I have : function auto_add_category ($product_id = 0) { if (!$product_id) return; $post_type = get_post_type($post_id); if ( "product" != $post_type ) return; $field = get_field("city"); if($field == "Cassis"){ $terms = get_the_terms( $post->ID, 'product_cat' ); foreach ($terms as

Only one currently added product into Woocommerce cart?

家住魔仙堡 提交于 2019-12-02 03:55:25
I would like Woocommerce to only allow 1 product in the cart. If a product is already in the cart and another one is added then it should remove the previous one. I found this code on net: /** * When an item is added to the cart, remove other products */ function custom_maybe_empty_cart( $valid, $product_id, $quantity ) { if( ! empty ( WC()->cart->get_cart() ) && $valid ){ WC()->cart->empty_cart(); wc_add_notice( 'Only allowed 1 item in cart, please remove previous item.', 'error' ); // here instead popup notice need to remove prevous added product } return $valid; } add_filter( 'woocommerce

product of list iteratively

人走茶凉 提交于 2019-12-02 03:55:19
I'm trying to learn coding in Haskell. I started with an easy example "the product of a list". product :: [Integer] -> Integer product [] = 1 product (x:xs) = x * product xs I finished this quickly. Another way is the product function in the API. (product List -> product) I wonder if there is another iterative way to solve my problem? You can use a fold: product :: Num a => [a] -> a product xs = foldl (*) 1 xs This can also be done strictly with foldl' or foldr , the differences mostly are performance, but since you're just starting out I'll skip that lecture this time. So what does a fold do?

Woocommerce custom availability text shown multiple times when selecting variations

耗尽温柔 提交于 2019-12-02 02:59:31
I'm experiencing the following bug on a clients WooCommerce website. We use this free Variations Swatch for Woocommerce plugin. I have a variable product with 4 different colors . If all colors are sold out, when selecting a variation the "out of stock" custom message is shown. But when selecting a different variation the message is shown again, so there are now 2 blocks with "out of stock" custom message: I have a different product in this store with color and engine variations and there's no issue like this. Question: How can I make the out of stock custom message to be shown only once at

Conditional product prices cart issue in WooCommerce 3

不问归期 提交于 2019-12-02 02:18:47
I modified a function to create custom prices for some of my members i.e. the normal price is $1 but if you're a bronze member it's $2, a silver member $3, etc. The prices are changed on the shop and single product page. When the product is added to the cart, however, the price reverts to the original amount. Is there additional code I should be including to have the price accurately changed all the way through checkout and billing? // Variations (of a variable product) add_filter('woocommerce_variation_prices_price', 'custom_variation_price', 99, 3 ); add_filter('woocommerce_variation_prices

Reduce product long description in Woocommerce

那年仲夏 提交于 2019-12-02 01:56:47
I have found the following code from this answer thread , but it only applied under the product title. So how can apply to the detailed description of the product. add_action( 'woocommerce_after_shop_loop_item_title', 'shorten_product_excerpt', 35 ); function shorten_product_excerpt() { global $post; $limit = 14; $text = $post->post_excerpt; if (str_word_count($text, 0) > $limit) { $arr = str_word_count($text, 2); $pos = array_keys($arr); $text = substr($text, 0, $pos[$limit]) . '...'; // $text = force_balance_tags($text); // may be you dont need this… } echo '<span class="excerpt"><p>' .

Reduce product long description in Woocommerce

空扰寡人 提交于 2019-12-02 01:45:33
问题 I have found the following code from this answer thread, but it only applied under the product title. So how can apply to the detailed description of the product. add_action( 'woocommerce_after_shop_loop_item_title', 'shorten_product_excerpt', 35 ); function shorten_product_excerpt() { global $post; $limit = 14; $text = $post->post_excerpt; if (str_word_count($text, 0) > $limit) { $arr = str_word_count($text, 2); $pos = array_keys($arr); $text = substr($text, 0, $pos[$limit]) . '...'; //