• rajeshsingh520

    (@rajeshsingh520)


    the product has a percentage discount configured using your discount plugin but

    When we are running WC()->cart->get_displayed_subtotal() inside our shipping method calcualaet_shipping() this returns wrong value of the product shipping method calcuate_shipping gets called multiple time and most of the time the subtotal is correct after discount price but on many occasion it consider the original cost of the product

    can you tell what function should we use instead of WC()->cart->get_displayed_subtotal() to get correct subtotal cost all the time

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    Can you share your code(only hook which call get_displayed_subtotal() ) and screeshot of the rule?

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    We have a shipping method that is created on this hook

    add_action( ‘woocommerce_shipping_init’, array( $this, ‘initShippingMethod’ ) );

    inside our shipping method there is

    class Efrs_Shipping_Method extends WC_Shipping_Method {

    function calculate_shipping(){

    //over here when we are running this

    WC()->cart->get_displayed_subtotal(); it is giving wrong subtotal

    }

    }

    here is screenshot of discount offer that we have created

    View post on imgur.com

    and we have identified that Tax setting has main role in this you need to have Tax setting like this

    View post on imgur.com

    Plugin Author algol.plus

    (@algolplus)

    Hi

    I used https://stackoverflow.com/questions/73509770/custom-woocommerce-shipping-method (code from 1st answer) to create new shipping method.

    I added this line to calculate_shipping(), as shown at https://snipboard.io/sRvSmg.jpg

                var_dump( WC()->cart->get_subtotal() + WC()->cart->get_subtotal_tax()  );

    I got correct results (I set discount 50%),
    another screenshot https://snipboard.io/BjgVaJ.jpg made in cart

    Please, try to disable all other plugins and check if you still see the problem.

    • This reply was modified 6 months ago by algol.plus.
    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    Thanks for checking it,

    we modified your code a bit here is the new shipping method for you to test. it is same as the one you used we have just modified the cost of the shipping to be dependent on the subtotal

    https://gist.github.com/rajeshsingh520/2dfbbd9ec2d20e8b55ab320d24cf8d6c

    make sure the product price is 57

    and tax is 21% (standard tax is configured )

    and discount is 29%

    See the total shown is incorrect (This test is done with all plugin disabled and only your plugin was running with woocommerce and the shipping method code was added through functions.php file )

    View post on imgur.com

    Plugin Author algol.plus

    (@algolplus)

    Do you use StoreFront theme ?

    Could you share your settings ? or better – submit them as new ticket to https://algolplus.freshdesk.com/

    Visit >Pricing Rules>Tools>Backup, select “options” in dropdown and copy this text.

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    No, we use Twenty Twenty theme and we even tested it with Twenty Twenty Four theme as well result is same

    Result is same even in the block based checkout page as well

    Plugin Author algol.plus

    (@algolplus)

    here is my results for block-based https://snipboard.io/PXQapl.jpg

    I need your settings

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    No we are not getting that result here is the test site login detail for you yo try out

    Site name: Detailed Class
    URL: https://detailedclass.s3-tastewp.com/
    Username: rajesh
    Password: wWouvUhNGeQ

    https://imgur.com/a/XLwBUk8

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    Here is a test site please check on this we have done all the configuration on this test site

    1. we have done the Tax setting
    2. we have added the shipping method code

    everything is done you have to add the product to the cart and go to the checkout page

    Site name: Detailed Class
    URL: https://detailedclass.s3-tastewp.com
    Username: rajesh
    Password: wWouvUhNGeQ

    View post on imgur.com

    Plugin Author algol.plus

    (@algolplus)

    hello

    I set shipping method , reloaded cart and I see “Flat rate” selected.

    Please, submit ticket to https://algolplus.freshdesk.com/ and remove test user now.
    It’s public forum.

    Plugin Author algol.plus

    (@algolplus)

    please, disable our plugin and test cart Total

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    We tested it with your plugin disabled, in that case subtotal is 68.97 which is more than 60 so the custom shipping method will not be shown as that shipping method is conditioned to show only when subtotal is more than 60 so with your plugin disabled it is working correctly

    View post on imgur.com

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Incorrect value of WC()->cart->get_displayed_subtotal()’ is closed to new replies.