Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Obtain coupon info
- This topic has 13 replies, 2 voices, and was last updated 6 years, 10 months ago by info17.
-
AuthorPosts
-
October 31, 2016 at 5:45 am #735info17Participant
How to obtain coupon info in functions?
i.e.
Coupon: Buy *** 4 Get *** freeI’d like to get *** and 4(number) to show a message on product page.
number be dynamic depend on items in the cart so static message is not I want.October 31, 2016 at 12:44 pm #736Soft79KeymasterMinimum amount of matching items:
get_post_meta( $coupon_id, '_wjecf_min_matching_product_qty', true )
(Where $coupon_id is the id of the coupon)Ids of the products that must be matched:
$coupon->product_ids
(Where $coupon is the WC_Coupon object)Free product ids:
WJECF_API()->get_coupon_free_product_ids( $coupon )
(Where $coupon is the WC_Coupon object, coupon id or coupon code)October 31, 2016 at 4:52 pm #739info17ParticipantThank you.
But in order to match product id with coupon, I have to gather all coupon data but single coupon with code.October 31, 2016 at 5:02 pm #740Soft79KeymasterYes, you’d have to query all existing coupons for that.
See https://www.skyverge.com/blog/get-a-list-of-all-woocommerce-coupons/.
November 1, 2016 at 1:34 am #743info17ParticipantThank you.
Is there anyway I can set certain product as free gift dynamically through a hook?
I want to change the product for free gift programmatically depend on situation but user select manually.November 1, 2016 at 12:41 pm #745Soft79KeymasterHi,
the product id’s are retrieved using this call:
get_post_meta( $coupon_id, '_wjecf_free_product_ids', true )
. It will go through the filterapply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
in wp-includes/post.php.So you can probably use the following snippet to manipulate the product ids:
add_filter( 'get_post_metadata', 'my_get_post_metadata', 10, 4 ); function my_get_post_metadata ( $meta_value, $object_id, $meta_key, $single ) { if ( $meta_key == '_wjecf_free_product_ids' ) { //EXAMPLE: replace the product id by 123 $meta_value = 123; } return $meta_value; }
You can use $object_id to retrieve the WC_Coupon object. (It’s the coupon id)
November 1, 2016 at 5:35 pm #748info17ParticipantI’d like to use Auto Coupon option but I want to let customer select free gift manually on other page than cart.
(So I don’t want to show gift selection element on cart page)
But I want free goods that is single selection to be added automatically.How to configure this?
November 1, 2016 at 11:54 pm #749Soft79KeymasterThe free gift is saved in the session. You can read the currently selected free item using:
WJECF_API()->get_session_selected_product( $coupon_code )
Setting the free item is not yet in the API of the plugin, but you can use the following method:
WJECF()->get_plugin('WJECF_Pro_Free_Products')->set_session_selected_product( $coupon_code, $product_id )
November 2, 2016 at 12:14 am #750info17ParticipantThank you.
How do I disable free gift selection on cart page?
Modify /template/cart/select-free-product.php?November 2, 2016 at 12:26 am #751Soft79KeymasterYou can override that file by placing it in wp-content/themes/YOUR-CHILD-THEME/woocommerce-auto-added-coupons/cart/select-free-product.php. Just place an empty file there.
Do the same for wp-content/themes/YOUR-CHILD-THEME/woocommerce-auto-added-coupons/checkout/select-free-product.php .
Make sure a free gift has been selected upon checkout. Otherwise the user can’t checkout.
November 3, 2016 at 8:18 pm #773info17ParticipantIs it possible to restrict rule to be applied to certain product using a hook?
I’m using this extension of WooCommerce Subscription
woocommerce-subscribe-all-the-things
https://github.com/Prospress/woocommerce-subscribe-all-the-thingsSince this extension handles regular product and subscription as one but variation, I can not filter out from GUI.
I need to check see if cart item has this value:
cart[id][wccsub_data][active_subscription_scheme_id]November 3, 2016 at 8:31 pm #775Soft79KeymasterUse the woocommerce_coupon_is_valid filter and return false to invalidate the coupon if the product is not in the cart.
November 3, 2016 at 9:24 pm #778info17ParticipantThank you.
But that filter apparently disables coupon itself if there is any match item.
So if customer have both a regular product and a subscription product in the cart, coupon will not be applied to any item.November 3, 2016 at 9:33 pm #779info17Participantanother filter woocommerce_coupon_is_valid_for_product worked!
-
AuthorPosts
- You must be logged in to reply to this topic.