Title: Issue with Custom Pricing Functionality When Using Your Plugin
Last modified: July 29, 2024

---

# Issue with Custom Pricing Functionality When Using Your Plugin

 *  Resolved [Mohammad Ridwanullah](https://wordpress.org/support/users/readonecc/)
 * (@readonecc)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/issue-with-custom-pricing-functionality-when-using-your-plugin/)
 * I am currently developing custom functionalities in WooCommerce to create a custom
   product type called “Tour.” This tour product has custom fields created with 
   ACF, and the price of the tour adjusts based on specific periods according to
   values entered in these fields. This functionality works correctly, and the price
   updates as expected on the frontend.
 * However, I encountered an issue when activating your plugin. The percentage-based
   pricing values entered in the custom fields are not being applied as expected.
 * Here is the code I am using:
 *     ```wp-block-code
       <?php// Update cart item price based on custom priceadd_action('woocommerce_before_calculate_totals', 'update_cart_item_price_based_on_tour_date', 10, 1);function update_cart_item_price_based_on_tour_date($cart) {    if (is_admin() && !defined('DOING_AJAX')) {        return;    }    // Get WooCommerce decimal settings    $decimal_places = get_option('woocommerce_price_num_decimals', 2);    $decimal_separator = get_option('woocommerce_price_decimal_sep', '.');    $thousand_separator = get_option('woocommerce_price_thousand_sep', ',');    foreach ($cart->get_cart() as $cart_item) {        if (isset($cart_item['tour_date'])) {            $product_id = $cart_item['product_id'];            $tour_date = $cart_item['tour_date'];            $tour_price = Izdone_Tour_Fields_Handler::get_tour_price_by_date($product_id, $tour_date);            if ($tour_price !== false) {                $base_price = get_post_meta($product_id, '_regular_price', true);                // Convert base price to float                $base_price = floatval(str_replace([$thousand_separator, $decimal_separator], ['', '.'], $base_price));                // Calculate new price                $new_price = $base_price * (1 + ($tour_price / 100));                // Format new price                $new_price = number_format($new_price, $decimal_places, $decimal_separator, $thousand_separator);                // Set new price                $cart_item['data']->set_price($new_price);            }        }    }}// Handle AJAX request to get tour price by dateadd_action('wp_ajax_get_tour_price', 'get_tour_price');add_action('wp_ajax_nopriv_get_tour_price', 'get_tour_price');function get_tour_price() {    $product_id = intval($_POST['product_id']);    $tour_date = sanitize_text_field($_POST['tour_date']);    $tour_price = Izdone_Tour_Fields_Handler::get_tour_price_by_date($product_id, $tour_date);    if ($tour_price !== false) {        wp_send_json(array('success' => true, 'price' => $tour_price));    } else {        wp_send_json(array('success' => false, 'price' => 0));    }    wp_die();}
       ```
   
 * Could you please assist me in resolving this issue? It appears that the custom
   pricing functionality is being affected by the activation of your plugin. I would
   appreciate any guidance or suggestions on how to ensure that the custom pricing
   works correctly alongside your plugin.
 * Thank you for your assistance.
 * Best regards

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * (@maartenbelmans)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/issue-with-custom-pricing-functionality-when-using-your-plugin/#post-17919568)
 * Hi [@readonecc](https://wordpress.org/support/users/readonecc/) 
   Our plugin only
   works with the standard WooCommerce product types “simple” and “variable”. Using
   them on a custom type is not recommended. Perhaps you can create a simple product
   that resembles a tour.
 *  Thread Starter [Mohammad Ridwanullah](https://wordpress.org/support/users/readonecc/)
 * (@readonecc)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/issue-with-custom-pricing-functionality-when-using-your-plugin/#post-17919618)
 * Thank you for your response. However, the issue is not related to using custom
   product types. The problem arises specifically when your plugin is activated;
   my custom functionality for dynamic pricing stops working as expected.
 * Could you please help identify which part of my custom functionality might be
   conflicting with your plugin? If possible, could you provide guidance on how 
   to troubleshoot or resolve this conflict?
 * I appreciate your assistance in resolving this issue.
 *  Plugin Author [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * (@maartenbelmans)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/issue-with-custom-pricing-functionality-when-using-your-plugin/#post-17919657)
 *  Hi [@readonecc](https://wordpress.org/support/users/readonecc/) 
   The issue *
   is* with the fact that your custom product has fields attached to it but these
   fields are not meant for that product type. We can not guarantee this will work
   in the future so I highly recommend not doing this. But if you want to go ahead
   at your own risk:Our plugin also hooks into `woocommerce_before_calculate_totals`
   so perhaps you should increase the priority on your code snippet from `10` to`
   20` to make sure it is the last in the sequence to run.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Issue with Custom Pricing Functionality When Using Your Plugin’ is closed
to new replies.

 * ![](https://ps.w.org/advanced-product-fields-for-woocommerce/assets/icon-256x256.
   gif?rev=3347990)
 * [Advanced Product Fields (Product Addons) for WooCommerce](https://wordpress.org/plugins/advanced-product-fields-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-product-fields-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/issue-with-custom-pricing-functionality-when-using-your-plugin/#post-17919657)
 * Status: resolved