woocommerce

Format billing phone number on WooCommerce checkout

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 18:08:59
问题 For the WooCommerce checkout billing field, how can I make this field require 9 numbers and insert dashes for proper phone formatting? For example, instead of typing out 3053453212 in the phone number field, it displays: (305-345-3212) 回答1: Based on "Formatting a phone number in a form using jquery" answer code, here is the way to format the Woocommerce billing phone: add_action('wp_footer', 'format_checkout_billing_phone'); function format_checkout_billing_phone() { if ( is_checkout() && !

Dynamic checkout custom fields per persons and items in Woocommerce bookings

折月煮酒 提交于 2021-02-18 17:55:44
问题 For a bookings website I'm trying to create a function which makes it possible to add an attendee list, based on the amount of persons. I've already got the code for a single booking, thanks to LoicTheAztec. That part is working fine. I also need the same functionality for multiple bookings. How can I achieve this? Here is the code: //* Add a new checkout field add_filter( 'woocommerce_checkout_fields', 'ppp_filter_checkout_fields' ); function ppp_filter_checkout_fields($fields){ $fields[

Woocommerce sort cart products by product category

▼魔方 西西 提交于 2021-02-18 08:46:40
问题 The Problem I would like to make it so my Woocommerce cart shows products in order of product category. (My products are assigned to a brand, and i want the products to appear in the cart area under their assigned brands.) What I have tried At the moment i've been able to get it to sort alphabetical by key however this is as far as my knowledge with arrays goes. Example Code add_action( 'woocommerce_cart_loaded_from_session', function() { global $woocommerce; $products_in_cart = array();

Additional columns and item values in Woocommerce email order details

假如想象 提交于 2021-02-18 08:03:24
问题 I am editing a Woocommerce email template but am a little stuck - I need to add a few columns to the order summary table so that it contains: Quantity Product Product code Price VAT I have added the table headers that I need into 'email-order-details.php' (copied to my theme's email folder) to but not sure how to get the actual content into the table. The code from the file is below: <?php /** * Order details table shown in emails. * * This template can be overridden by copying it to

Additional columns and item values in Woocommerce email order details

爱⌒轻易说出口 提交于 2021-02-18 08:03:24
问题 I am editing a Woocommerce email template but am a little stuck - I need to add a few columns to the order summary table so that it contains: Quantity Product Product code Price VAT I have added the table headers that I need into 'email-order-details.php' (copied to my theme's email folder) to but not sure how to get the actual content into the table. The code from the file is below: <?php /** * Order details table shown in emails. * * This template can be overridden by copying it to

Add a product add-on field to specific products on WooCommerce

一个人想着一个人 提交于 2021-02-17 03:22:57
问题 I need to change the code to not display text area on all of my WooCommerce products but only 2, this is on my WordPress child theme under functions.php file. I have changed $product_id to $product_id = 2130 (my specific product id) , not sure if I'm supposed to change all the $product_id or $_POST for this code to display on only 2 products It is for a specific product or products that gets personalized with a name. I have tried changing the code $product_id to numerous other extensions to

WooCommerce custom report: Get orders with completed status

梦想的初衷 提交于 2021-02-17 02:50:08
问题 im making a custom reports for woocommerce im trying to add a report for all delivered orders here is what im doing $orders = wc_get_orders( array('numberposts' => -1) ); foreach( $orders as $order ){ if ( $order->get_status() === completed){ $order_data = $order->get_data(); // The Order data $items = $order->get_items(); foreach ( $items as $item ) { $product_name = $item->get_name(); $product_id = $item->get_product_id(); } $orders_completed .= '<tr><td>' . $order->get_order_number() . '<

Prevent add to cart if cart contains a specific category (WooCommerce)

限于喜欢 提交于 2021-02-16 21:24:46
问题 I have a store containing 5 categories. It's multivendor and due to shipping complications, I can only sell products from one specific category ('paint') when they are alone in the cart. So I need to prevent add to cart of any non-paint products when the cart contains paint, and display an error message, and I need to prevent paint products being added to a cart containing any other categories, and disaply an error message. I've tried to cobble together this code from snippets I've found

Conditionally hide Woocommerce checkout custom field based on free shipping

只谈情不闲聊 提交于 2021-02-16 20:19:30
问题 In WooCommerce, I am trying to hide one custom added field whenever "free delivery" is selected (automatic selection, based on order amount). I was thinking that I found a solution with code below, but when I load a page on new (incognito) browser window, the field is present and if refresh it, the field is hidden again. // Hide address field, when Free Shipping mode is selected add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields'); function xa_remove_billing_checkout

Hide a variation attribute value in Woocommerce variable product dropdown

泪湿孤枕 提交于 2021-02-16 20:14:34
问题 I want to hide specific variations from being shown in the dropdown of woocommerce product pages. I was able to hide the "choose an option" but I am struggling with doing the same for the value="2,5 kg" for example This is my code for hiding "choose an option": add_filter( 'woocommerce_dropdown_variation_attribute_options_html', 'remove_choose_an_option'); function remove_choose_an_option( $html ){ $html = str_replace('<option value="">' . __( 'Choose an option', 'woocommerce' ) . '</option>'