hook-woocommerce

How to disable shipping completely for a WooCommerce product type?

混江龙づ霸主 提交于 2020-01-02 07:02:39
问题 I would like to disable requirement to select shipping method for a particular product type (here "booking" product type) on the checkout. So they should be able to buy product without shipping method. 回答1: To disable shipping completely* when a specific product type is in cart you will use the following: add_filter( 'woocommerce_cart_needs_shipping', 'filter_cart_needs_shipping_callback' ); function filter_cart_needs_shipping_callback( $needs_shipping ){ foreach ( WC()->cart->get_cart() as

WooCommerce Conversion Tracking Script for two Pixel

强颜欢笑 提交于 2019-12-31 06:56:06
问题 I want to promote my products by some affiliate networks. Do only thing you have to do, is to go into the function.php file and add this script with the pixel. With this script the tracking of the amount value works fine. This script works only for one network and if you are the only vendor. add_action( 'woocommerce_thankyou', 'my_custom_tracking' ); function my_custom_tracking( $order_id ) { $order = new WC_Order( $order_id ); $total = $order->get_subtotal(); $id = str_replace('#', '',

Rename Add to Cart buttons for Out Of Stock Products in WooCommerce 3

纵然是瞬间 提交于 2019-12-31 03:45:07
问题 I would like to rename 'Add to Cart' to 'Sold Out' when product is sold out in WooCommerce. This is my code: add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // 2.1 + function woo_custom_single_add_to_cart_text() { if( $product->get_stock_quantity() == 0 ) return __( 'Sold Out', 'woocommerce' ); } else { return __( 'Add to cart ', 'woocommerce' ); } But it's not working.

Add custom Product data dynamically as item meta data on the Order

风流意气都作罢 提交于 2019-12-29 08:08:09
问题 Is it possible to add a metadata on a product which is inside the Order? In this case, there would be one metadata but each product (in the order) would have different value. Example: Order 1: * Product 1 Sample Meta: Meta1 * Product 2 Sample Meta: Meta2 Thanks. Update1 : I'm now stuck on how would I grab the values from the woocommerce_add_cart_item_data filter. I was able to successfully add the meta data from there. I need to grab those values for me to use in this woocommerce_add_order

Hooks around add to cart for Woocommerce

落花浮王杯 提交于 2019-12-29 01:28:10
问题 I am running a WooCommerce store with WC Marketplace. What I am trying to achieve with the hook below is to prevent a new item being added to a basket if there is already a product in the basket from a different vendor. e.g. If a shopper adds product x from vendor y to his basket, if they were to add product a from vendor b, then the item will not be added and the user will be informed of the error. I have 2 questions: - firstly when does a hook run, is it before the main function fired or

How to add custom fields to WooCommerce registration form

南笙酒味 提交于 2019-12-28 18:53:48
问题 I have seen similar questions but couldn't find a solution for me. I am trying to add custom fields to WooCommerce registration form, specifically first and last name field. I have managed to create these fields but the information entered does not pass over to the Account Details page when the user has logged in. Other tutorials have mentioned validating the fields but I am not sure is it relevant to me or not. I am working on a Wordpress child theme. Please visit to codepad .org to view the

How to remove nofollow link from woocommerce add to cart button using woocommerce_loop_add_to_cart_link hook?

允我心安 提交于 2019-12-25 18:32:46
问题 I added this to functions.php. Is there any best solution than this? apply_filters( 'woocommerce_loop_add_to_cart_link', global $product; return sprintf( '<a href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $quantity ) ? $quantity : 1 ), esc_attr( $product->get_id() ), esc_attr( $product->get_sku() ), esc_attr( isset( $class ) ? $class : 'button' ), esc_html( $product->add_to_cart_text() ) ),

Woocommerce format price display of cart calculated fees

别等时光非礼了梦想. 提交于 2019-12-25 03:18:16
问题 I am manually modifying the price of the cart total (to £10) when there are 4 items in the cart and none of the items are from the category: christmas . This essentially gives the user a discount + "Free Shipping" . However, the total does not match up and it can be confusing to the user as shipping is still shown as charged. Is there a way to manually apply a dummy "Free Shipping Applied -£3.00" to the cart based on these conditions? Just to make it clearer for the user? I understand that

Add a custom orderby search in WooCommerce

瘦欲@ 提交于 2019-12-25 00:16:16
问题 I would like to add a custom search order to my theme that will sort products by page views. I already installed a Post Views Counter plugin to get the page views. Plugin documentation is available here. I found following code on WooCommerce documentation: add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby']

How to update similar variation stock after purchase in Woocommerce

一世执手 提交于 2019-12-24 19:42:39
问题 I struggle to find a way to update the stock of the similar variation of a product. All my product have, say, a main variation, "Black" (30$) or "white" (250$) but sometimes they have another variation which is a "date start", so date_start:"12th june", date_start: "30th july", etc. I need to update the stock of the "date" variation when it's present (if there is no date, woocommerce update the main stock, no problem). If someone choose "Black"+"12th June" I need the stock of "12 June" to be