cart

Set “flat rate” shipping method as default in woocommerce

本秂侑毒 提交于 2021-02-05 11:12:24
问题 I have a woocommerce website and I have set 2 shipping methods: - Flat Rate - Local pickup I would like to set the "Flat rate" shipping method as default (selected) in the cart or checkout page. Any help should be appreciated. 回答1: 1) You can use the following code (to set "flat rate" shipping method as default) In cart page: add_action( 'woocommerce_before_cart', 'set_default_chosen_shipping_method', 5 ); function set_default_chosen_shipping_method(){ // if( count( WC()->session->get(

Set “flat rate” shipping method as default in woocommerce

僤鯓⒐⒋嵵緔 提交于 2021-02-05 11:10:23
问题 I have a woocommerce website and I have set 2 shipping methods: - Flat Rate - Local pickup I would like to set the "Flat rate" shipping method as default (selected) in the cart or checkout page. Any help should be appreciated. 回答1: 1) You can use the following code (to set "flat rate" shipping method as default) In cart page: add_action( 'woocommerce_before_cart', 'set_default_chosen_shipping_method', 5 ); function set_default_chosen_shipping_method(){ // if( count( WC()->session->get(

Conditionally adding or removing a free product in cart

青春壹個敷衍的年華 提交于 2021-02-05 08:47:09
问题 I've a function in woocommerce that add automatically to cart a free gift. I would like to add this based on minimum quantity of 15 i've this code that works, but when i update the cart don't remove the item if the quantity is not 15. How I can automatic remove product when I update the cart if total id different to 15 ? } //add_action( 'init', 'wcsg_add_product_to_cart' ); add_action( 'wp_loaded', 'wcsg_add_product_to_cart', 99 ); function wcsg_add_product_to_cart() { if ( ! is_admin() ) {

Conditionally adding or removing a free product in cart

▼魔方 西西 提交于 2021-02-05 08:47:06
问题 I've a function in woocommerce that add automatically to cart a free gift. I would like to add this based on minimum quantity of 15 i've this code that works, but when i update the cart don't remove the item if the quantity is not 15. How I can automatic remove product when I update the cart if total id different to 15 ? } //add_action( 'init', 'wcsg_add_product_to_cart' ); add_action( 'wp_loaded', 'wcsg_add_product_to_cart', 99 ); function wcsg_add_product_to_cart() { if ( ! is_admin() ) {

Allow proceed to checkout for non mixed defined product categories in Woocommerce

独自空忆成欢 提交于 2021-02-05 08:31:44
问题 In woocommerce I am trying to avoid proceed to checkout when cart items are from mixed product categories… The following code is mostly working as I intended: function sv_wc_prevent_checkout_for_category() { // set the slug of the category that cannot be mixed from other categories $category = 'test'; // get the product category $product_cat = get_term_by( 'slug', $category, 'product_cat' ); // sanity check to prevent fatals if the term doesn't exist if ( is_wp_error( $product_cat ) ) {

Minumun cart amount except for several specific products in WooCommerce

痞子三分冷 提交于 2021-02-04 08:13:08
问题 I'm using the following code "Minimum cart amount except for a specific product in Woocommerce" in my php that allows the override of the Woocommerce minimum cart value of $130. Works fine but only for one defined product. In this case product_id 2649 I am trying to further modify this code by adding lines of except_product_id... but that does not help. How can I modify to make a list of exceptions by product id ? Any help appreciated add_action( 'woocommerce_check_cart_items', 'min_cart

Minumun cart amount except for several specific products in WooCommerce

北慕城南 提交于 2021-02-04 08:11:09
问题 I'm using the following code "Minimum cart amount except for a specific product in Woocommerce" in my php that allows the override of the Woocommerce minimum cart value of $130. Works fine but only for one defined product. In this case product_id 2649 I am trying to further modify this code by adding lines of except_product_id... but that does not help. How can I modify to make a list of exceptions by product id ? Any help appreciated add_action( 'woocommerce_check_cart_items', 'min_cart

Override woocommerce cart item price with product custom field value

时间秒杀一切 提交于 2021-02-04 07:36:33
问题 In woocommerce I am using Advanced Custom Fields and trying to get a custom field value in each product as price instead of the default product price. this custom field is called 'custom_price' . How can I change this hard coded value to use that instead? Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $cart_object ) { $custom_price = 10; foreach ( $cart_object->cart_contents as $key => $value ) { $value['data']->set_price(

Override woocommerce cart item price with product custom field value

筅森魡賤 提交于 2021-02-04 07:36:03
问题 In woocommerce I am using Advanced Custom Fields and trying to get a custom field value in each product as price instead of the default product price. this custom field is called 'custom_price' . How can I change this hard coded value to use that instead? Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $cart_object ) { $custom_price = 10; foreach ( $cart_object->cart_contents as $key => $value ) { $value['data']->set_price(

Minimum cart amount for specific product categories in WooCommerce

我的梦境 提交于 2021-02-01 05:13:47
问题 In WooCommerce I use an OUTLET category with on sale products and I would like to set a minimum subtotal (30 €) for customers purchasing any "Outlet" product. I tried to hook into woocommerce_after_calculate_totals to: check cart items for a specific product category display a notice when a specific product category is found and the order is lower than 30 € and eventually redirect to cart page when user tries to checkout with an order lower than 30 €. Here is my code: add_action( 'woocommerce