Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter raulis

    (@raulis)

    The plugin, I am using does not update price at back end. So, the discounted price will might not be reflected.

    I found this documentation to get price:

    https://docs.flycart.org/en/articles/7907342-developer-documentation

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    GTM Kit is only adding discount based on coupons.

    You can use the filter gtmkit_datalayer_item_data (https://github.com/tlamedia/gtm-kit/blob/main/src/Integration/WooCommerce.php#L685) to add the discount and discounted price.

    Create a filter for gtmkit_datalayer_item_data that applies the advanced_woo_discount_ filters.

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Have you tried my sugestion?

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Closing this

    Thread Starter raulis

    (@raulis)

    Sorry for late replay. Could you please provide me an example of how does this work? How one would apply the filter and and add extra data to it?

    Thank you!

    Thread Starter raulis

    (@raulis)

    I have managed to create and use the filter to add discount information like sale price and discount amount, but at the same time, I am getting several errors. Most likely because of my crooked code ??

    Here is the code:

    add_filter( 'gtmkit_datalayer_item_data', 'gtm_kit_edit', $priority = 10, $accepted_args = 3  );
    
    function gtm_kit_edit( $item_data, $product, $event_context ) {
    	if ( is_product() ) {
    		$discount_data = [];
    		$sale_price = round(apply_filters('advanced_woo_discount_rules_get_product_discount_price', $product->get_price(), $product),2);
    		if ($sale_price != $item_data['price']) {
    			$discount = round($item_data['price'] - $sale_price,2);
    			$discount_data = [
    					'sale_price' => $sale_price,
    					'discount'     => $discount,
    			];
    			$item_data = array_merge( $item_data, $discount_data );
    		}
    		return $item_data;
    	}
    	return null;
    }

    1) I am getting this crazy pile of code on the cart page for eample, catalog pages are also broken: https://drive.google.com/file/d/1A0OqDaJO1ckIyGQgfiWMtW3tOFdE0ufY/view?usp=drivesdk

    2) Some undefined events started to be generated: https://drive.google.com/file/d/1oBYOWi4pPQA-61qaWl3azvXkhNM9Kwuo/view?usp=drivesdk

    3) this ajax error appears when cart is not empty: https://drive.google.com/file/d/1vd1pBSXwFZSPjV4qlyDAmVJDnf_xU1K0/view?usp=drivesdk

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Try this:

    function gtm_kit_edit( array $item_data, WC_Product $product, string $event_context ): array {
    	$sale_price = round(apply_filters('advanced_woo_discount_rules_get_product_discount_price', $product->get_price(), $product),2);
    	if ($sale_price != $item_data['price']) {
    		$discount = round($item_data['price'] - $sale_price,2);
    		$item_data['sale_price'] = $sale_price;
    		$item_data['discount'] = $discount;
    	}
    	return $item_data;
    }

    You must always return the first parameter of a filter, which in this case is $item_data.

    $product is always of the type WC_Product so there is no need to test that.

    is_product() checks if you are on a product page so on all other types of pages you returned null which is the root cause of you problems.

    Thread Starter raulis

    (@raulis)

    That works perfectly now. Thank you.

    Just to make sure, this code only gets run on woocommerce pages as it is a filter to your function that is run on woo pages only?

    Also how can I round up the value in cart/payment pages: https://drive.google.com/file/d/1jCUJDqmE0E5xbBTpKrEyUDrLZIFFk4VY/view?usp=drivesdk

    And is it possible to add total discount value for whole cart event?

    Thread Starter raulis

    (@raulis)

    Have also noticed, that quantity is not being added from catalog side.

    • This reply was modified 1 year, 2 months ago by raulis.
    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    The code only runs on Woo pages when GTM Kit is active. So if you deactivate GTM Kit your site will function as normal.

    You can filter the whole data layer using the filter gtmkit_datalayer_content change anything you want.

    I can confirm that quantity is not being added from a catalog page and i will make a fix.

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    The quantity bug is now fixed and vill be included in the next release

    Thread Starter raulis

    (@raulis)

    I also noticed, that on every quantity increase there is an undefined event created. Not sure if it is intended so.

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    In GTM or a console error?

    Thread Starter raulis

    (@raulis)

    I see in console. Not sure about GTM.

    Would it be possible to add select_item event when item in catalog is clicked?

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Closing this as resolved

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Discount is not counted’ is closed to new replies.