cart

Custom cart items price calculation for Woocommerce Bookings

戏子无情 提交于 2019-12-12 23:17:39
问题 I want to know how to update the price calculation depending on some internal coding. This is the price that needs to go into the cart item and thus far, the cart item shows only the base cost of the product. Technically the price should be altered, when a product is added to the cart. I figured it had to be calculated like this: global $woocommerce; $items = $woocommerce->cart->get_cart(); foreach($items as $item => $values) { if ($value['product_id'] == $product_id) { $value['data']->set

Playing MP3 songs without disclosing the path of the file

戏子无情 提交于 2019-12-12 23:09:22
问题 I am developing a shopping cart in PHP where i will sell the Songs in MP3 format. With product display i would like to provide the visitors/users to listen the Song 1 time only. So if i use players like JW player to play the song. The player disclose the file path in the source code of the web page and they can download the file directly. What i am looking for it to play the song so that visitors does not know the path of the song file. How can i avoid this ? Please advice. Thanks 回答1: You

Change number of decimals in Woocommerce cart totals

喜你入骨 提交于 2019-12-12 20:18:26
问题 In Woocommerce, I've set the number of decimal to 7 on in Woocommerce general settings, so I can display the product price like this $0.0453321 . I'm wondering if I can set/round the cart total to only 2 decimals (something like this $2.34 )? 回答1: The correct way is to change just the number of allowed decimals for cart and checkout pages only: add_filter( 'wc_get_price_decimals', 'change_prices_decimals', 20, 1 ); function change_prices_decimals( $decimals ){ if( is_cart() || is_checkout() )

Change number of decimals on Woocommerce displayed cart subtotal

。_饼干妹妹 提交于 2019-12-12 17:20:11
问题 I am Using "Change number of decimals in Woocommerce cart totals" answer code to display the total with 2 decimals . The code works fine for the displayed total in cart and checkout pages. I would like if possible to do the same thing for the subtotal too. Any help is appreciated. 回答1: To format the displayed subtotal amount with 2 decimals in cart and checkout pages use the following: // Displayed formatted cart subtotal in cart and checkout pages add_filter( 'woocommerce_cart_subtotal',

Auto apply coupon only one time per user based on total spent in WooCommerce

余生长醉 提交于 2019-12-12 16:33:25
问题 I would like to apply a coupon automatically based on customer total spent amount. This coupon needs to be applied only one time by customer. This is what I've tried so far but I'm getting a blank screen: add_action( 'woocommerce_before_calculate_totals', 'loyalty_order_discount', 10, 1 ); function loyalty_order_discount( $order_id ) { global $woocommerce; $coupon = 'loyaltydiscount'; $customer = new WC_Customer(get_current_user_id()); $total_spent = 30; $order = wc_get_order( $order_id );

Adding a discount by cart items conditionally based on the item quantity

时光总嘲笑我的痴心妄想 提交于 2019-12-12 15:35:26
问题 I have set up a Woocommerce shop and wish to set up a specific discount on all products based on multiples of 12 (a box). I've tried many discount plugins but haven't found what I am looking for. For example, if I order 12 of product X, I get a 10% discount. If I order 15 of product X, I get a 10% discount on the first 12, and the last three are full price. If I order 24, then that 10% discount applies to all 24 of product X. The closest I have found is this: Discount for Certain Category

Checking that a specific attribute value is used in a cart Item (product variation)

若如初见. 提交于 2019-12-12 13:12:38
问题 In WooCommerce, I would like to check if the products in the shopping cart have the attribute 'Varifocal' (so I can show/hide checkout fields). I'm struggling to get an array of id's of all the variations which have the attribute 'varifocal'. It would be really appreciated if someone can point me in the right direction. The taxonomy is pa_lenses . I currently have the following function: function varifocal() { // Add product IDs here $ids = array(); // Products currently in the cart $cart_ids

Null cart item price for a specific product category in Woocommerce

老子叫甜甜 提交于 2019-12-12 04:15:48
问题 I want to remove / takeout the price of a specific category products from Cart Total. Please see this screenshot: What hook could I use to do this? Thanks. 回答1: The right hook to do that is woocommerce_before_calculate_totals using has_term() WordPress conditional function to filter product categories in cart items. This way you can null the price for that cart items. This is the code (added compatibility for Woocommerce 3+) : add_action( 'woocommerce_before_calculate_totals', 'custom_price

Get ALL woocommerce cart item names

纵然是瞬间 提交于 2019-12-12 04:13:37
问题 I am trying to send the woocommerce cart items to third party tool. I need the item name. $items = $woocommerce->cart->get_cart(); foreach($items as $item => $values) { $_product = $values['data']->post; echo $_product->post_title; } I can get the cart item names like that. But i cannot do it like this for the following reason. I need to store the cart item name in an array which will be sent to the third party tool I mentioned earlier. $sales_payload = array( 'organization_id' =>

Woocommerce conditional part cart discount on the same product present with > 1 variation

只愿长相守 提交于 2019-12-12 03:48:16
问题 My woocommerce products are actually cruise expeditions (two products = two expedition types). For each product, the variations consists of the weeks in which cruises take place (= dates). So I have Ligurian Sea Expeditions with 20 different weeks and Greece Expeditions with other 20 weeks. Fortunately I have just 2 products like that to deal with (a very simple situation) The customer usually chooses one week expedition. However I need to apply a 10% discount on the second (or third) week in