• Resolved Group Of Oceninfo

    (@princebhalani143)


    Hello Team,

    I’ve updated the latest version, and the customs cost field is not overwriting the product cart price.

    Previously, when a user entered the custom value, it picked up the custom value. Now, it’s just adding $2 as product meta instead of overwriting the product cost for the cart/checkout page. i.e. instead of $1, if users would like to pay $2, they can add that to the cart without affecting the product price. You can test the same behaviour with 3.0.4.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Sark

    (@sarkware)

    Hi, I checked the link you shared, there is no pricing rule set for that product.
    I checked the pricing rules meta for that product there is none set.

    I don’t think the custom amount scenario will work with WC Fields Factory, using the pricing rules you can add, subtract or replace the fixed / percent amount (the amont which set by the rules).

    Here you wanted, whatever the customer entered on that text field should be added with the product price right.? (I assume that is the case, if not pls update me)

    If that is case, let me know. I will send you a snippet which will achive that for you.

    Thread Starter Group Of Oceninfo

    (@princebhalani143)

    @sarkware Thanks for the response, Instead of the default $1, whatever customer enters in the custom text field should be added to the cart.

    For example, if the customer wants to pay only $2, then it’ll pick up the $2 instead of $1 when the customer enters 2 in the input field. I’ve also tried setting up price rules (see screenshot below) but no luck so far.

    Pricing Rules

    Field Rules

    Please note it was working smoothly in version 3.0.4 without setting any price rules.

    Thread Starter Group Of Oceninfo

    (@princebhalani143)

    Hello Team,

    As I’ve mentioned earlier we don’t need pricing rules or field rules, we can do this using the below code under functions.php

    // Updating cart item prices conditionally
    add_action( 'woocommerce_before_calculate_totals', 'custom_cart_item_price', 100, 1 );
    function custom_cart_item_price( $cart ) {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        // add product categories to avoid
        $categories = array("uncategorised", "general");
    
        foreach ( $cart->get_cart() as $cart_item ) {
            if( isset($cart_item['wccpf_cost']['user_val']) && ! has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
                $cart_item['data']->set_price($cart_item['wccpf_cost']['user_val']);
            }
        }
    }

    Note: Replace wccpf_cost with dynamically generated input name.

    Plugin Contributor Sark

    (@sarkware)

    @princebhalani143 Great to see you worked this out.

    As I mentioned in my previous reply, I was talking about the same kind of snippet that I wouldd have send. As using the built in pricing rule module we cannot achive that.

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

The topic ‘New Version Custom Cost Issue’ is closed to new replies.