price

Add a custom product calculated price to Woocommerce cart

北战南征 提交于 2019-12-01 07:36:35
问题 In woocommerce I have added an extra text field before add to cart button to add custom charge on product purchase. This plugin will add extra text field to single product page and calculates total plus the extra charge. My problem is that I cant add custom cart totals and the extra charge add before totals I tried woocommerce_cart_calculate_fees but no luck it only show $0 in totals PHP code: /** * Check if woocommerce is active and or installed. */ if ( class_exists( 'WooCommerce' ) || in

Get the product price in Woocommerce 3

别来无恙 提交于 2019-12-01 06:34:58
问题 I'm trying to get price without currency in a function I made. function add_price_widget() { global $woocommerce; $product = new WC_Product(get_the_ID()); $thePrice = $product->get_price_html(); echo thePrice; } Displays: 100kr How do I get it to just give me the price 100 回答1: What @Syntax_Error had said is correct you have to use get_price(), WooCOmmerce also provide a wrapper function wc_get_product() for WC_Product class. So your function would look something like this: function add_price

Identify a value changes' date and summarize the data with sum() and diff() in R

拥有回忆 提交于 2019-12-01 06:01:08
问题 Sample Data: product_id <- c("1000","1000","1000","1000","1000","1000", "1002","1002","1002","1002","1002","1002") qty_ordered <- c(1,2,1,1,1,1,1,2,1,2,1,1) price <- c(2.49,2.49,2.49,1.743,2.49,2.49, 2.093,2.093,2.11,2.11,2.11, 2.97) date <- c("2/23/15","2/23/15", '3/16/15','3/16/15','5/16/15', "6/18/15", "2/19/15","3/19/15","3/19/15","3/19/15","3/19/15","4/19/15") sampleData <- data.frame(product_id, qty_ordered, price, date) I would like to identify every time when a change in a price

WooCommerce Price overriding not working

本小妞迷上赌 提交于 2019-12-01 00:44:04
I have set up a hidden input item using woocommerce_before_add_to_cart_button hook function add_gift_wrap_field() { ?>`<input type="hidden" id="price_val" name="added_price" value="100.34">`<?php } add_action( 'woocommerce_before_add_to_cart_button', 'add_gift_wrap_field' ); Saving fields against the product: function save_gift_wrap_fee( $cart_item_data, $product_id ) { if( isset( $_POST['added_price'] ) ) { $cart_item_data = array(); $cart_item_data[ "gift_wrap_fee" ] = "YES"; $cart_item_data[ "gift_wrap_price" ] = 100; } return $cart_item_data; } add_filter( 'woocommerce_add_cart_item_data',

Set cart item product generated sale price only for specific products in Woocommerce

假装没事ソ 提交于 2019-11-29 16:56:09
Following Set only specific products sale price programmatically in WooCommerce 3 , the related cart items price are not updated with the product's generated sale price. How can I get the generated sale price for specific products, in the related cart items? Any help is appreciated. To get the right generated sale price in cart item for specific product IDs try the following: // HERE below in the array set your specific product IDs function specific_product_ids(){ return array(37, 41); // <=== <=== <=== <=== Your Product IDs } // Generating dynamically the product "regular price" add_filter(

Replace WooCommerce variable products price range with 'Up to' and the max price

北战南征 提交于 2019-11-29 16:47:24
I found the following code (from here ) which enables me to show on a variable price product on WooCommerce: ' From: £10 ' (on a £10 - £50 product). I would like to effectively reverse this and show ' Up to: £50 '. I have tried to tweak the code below, but just can't figure it out: function custom_variable_price_range( $price_html, $product ) { $prefix = sprintf('%s: ', __('From', 'woocommerce') ); $min_regular_price = $product->get_variation_regular_price( 'min', true ); $min_sale_price = $product->get_variation_sale_price( 'min', true ); $max_price = $product->get_variation_price( 'max',

Conditionally alter specific product price in Woocommerce

╄→尐↘猪︶ㄣ 提交于 2019-11-29 16:10:09
I would like to alter a specific product in Woocommerce, adding programmatically to its original an amount of $10, EXCEPT in those cases : On specific product pages that are bookable products for hire (Woocommerce Bookings) that belongs to a certain Category "C". If any cart item belongs to that category "C". I was using this answer code to one of my questions until now. But I should need to display this specific product altered price everywhere except on that product pages that are bookable products, in front end. I have also this code that displays the Force Sells price beside the titles.

Set product sale price programmatically in WooCommerce 3

让人想犯罪 __ 提交于 2019-11-29 11:31:57
I have a Woocommerce store set up with various product categories. I want to apply a 20% discount to all products, which belong to the product category Cuckoo For now all I'm trying to achieve is set a sale price in my functions.php It tried as follows: /* * For a specific date, 20% off all products with product category as cuckoo clock. */ function cuckoo_minus_twenty($sale_price, $product) { $sale_price = $product->get_price() * 0.8; return $sale_price; }; // add the action add_filter( 'woocommerce_get_sale_price', 'cuckoo_minus_twenty', 10, 2 ); If I var_dump the result of $sale_price after

Display the discounted price and percentage on Woocommerce products

只谈情不闲聊 提交于 2019-11-28 21:59:35
On the image below, it shows the discounted price and percentage I found no custom code searching that has this feature. I am using the code below to display the discounted price, but the price is not formatted (the currency symbol and the decimals are missing): add_filter( 'woocommerce_get_price_html', 'modify_woocommerce_get_price_html', 10, 2 ); function modify_woocommerce_get_price_html( $price, $product ) { if( $product->is_on_sale() && ! is_admin() ) return $price . sprintf( __('<p class="saved-sale">Save: %s</p>', 'woocommerce' ), $product->regular_price - $product->sale_price ); else

WooCommerce variable products: keep only “min” price with a custom label

牧云@^-^@ 提交于 2019-11-28 14:15:30
In the functions file I have added a filter hook to add a custom label before the variation product "min" price. How can I get the label in the same line as the price? See my code and the screenshot below: add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); function wc_wc20_variation_price_format( $price, $product ) { $min_price = $product->get_variation_price( 'min', true ); $price = sprintf( __( 'From%1$s', 'woocommerce' ), wc_price( $min_price ) ); return