product

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() ) {

Check a product category for a product in Woocommerce

女生的网名这么多〃 提交于 2021-02-05 08:16:06
问题 I want to check the category of a WooCommerce product post right after it's created(or updated) and then run some more code based on the category. To check post on creation/update I used save_post and for category has_category . Something goes wrong with has_category and it doesn't return anything at all. I tried replacing $post_id with $post and $post->ID as suggested in other issues but that didn't change anything. function doFruitStuff($post_id){ // Function in functions.php $fruits =

Add sorting by stock quantity in WooCommerce products sort by

我的梦境 提交于 2021-02-04 21:42:36
问题 I have added the following code to my theme functions.php . The "Availability" sort option does show up but when I select it, it is sorted by Title, not stock quantity. I also tried using stock_quantity as a meta_key (even though it's not a meta) and that didn't work either. 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

Add sorting by stock quantity in WooCommerce products sort by

余生颓废 提交于 2021-02-04 21:42:30
问题 I have added the following code to my theme functions.php . The "Availability" sort option does show up but when I select it, it is sorted by Title, not stock quantity. I also tried using stock_quantity as a meta_key (even though it's not a meta) and that didn't work either. 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

Allow only one item in cart from defined product categories in Woocommerce

梦想与她 提交于 2021-02-04 16:30:10
问题 In Woocommerce, I found a bit of code that restricts a users purchase to one per category for category a or b. So currently the user could purchase 2 items 1 from cat a and 1 from cat b. I would like to limit the user to only one product from category a or b. The code I am working with is below, thanks in advance. add_filter( 'woocommerce_add_to_cart_validation', 'allowed_quantity_per_category_in_the_cart', 10, 2 );function allowed_quantity_per_category_in_the_cart( $passed, $product_id) {

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

Show Price Suffix only on all WooCommerce Product loops

*爱你&永不变心* 提交于 2021-02-04 07:51:09
问题 I have an online shop with WooCommerce. I want to show a custom price Suffix only on the Product List Page (like Shop Page), where all products are listed. I have the following code: add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 ); function custom_price_suffix( $price, $product ){ $price = $price . ' Suffix '; return apply_filters( 'woocommerce_get_price', $price ); } But with this code, the suffix is display in the Product list Page and on single Products. Can

Show Price Suffix only on all WooCommerce Product loops

强颜欢笑 提交于 2021-02-04 07:50:56
问题 I have an online shop with WooCommerce. I want to show a custom price Suffix only on the Product List Page (like Shop Page), where all products are listed. I have the following code: add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 ); function custom_price_suffix( $price, $product ){ $price = $price . ' Suffix '; return apply_filters( 'woocommerce_get_price', $price ); } But with this code, the suffix is display in the Product list Page and on single Products. Can