Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get cart totals on JS #28

Closed
seldimi opened this issue Jan 24, 2024 · 4 comments
Closed

Get cart totals on JS #28

seldimi opened this issue Jan 24, 2024 · 4 comments

Comments

@seldimi
Copy link

seldimi commented Jan 24, 2024

Hello
import { useCart } from '@woocommerce/blocks-checkout';
Can you give an example or least document how to get the cart (eg cart totals, as the above one fails

@PanosSynetos
Copy link
Collaborator

@senadir could you maybe help here? Thanks!

@mikejolley
Copy link
Member

Hi,

The @woocommerce/blocks-checkout package exports only some components that payment methods can use. useCart does not exist—I'm not sure where you saw that example.

How you access cart totals depends on your use case. They are available from the REST API, or some components are passed these values for context. For example, payment methods will be given the cart totals and customer address information.

I'd suggest starting here:

https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility

And for payment method specifically look here:

https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md

An example of cart data, if you look at the canMakePayment method, its passed a cart object which holds everything you need:

https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md#canmakepayment-required

I will mark this closed as this is unrelated to this repository. You can ask questions on WooCommerce Community Slack if you need further assistance. Thanks

@seldimi
Copy link
Author

seldimi commented Jan 26, 2024

Hello.
Yes I understood this is not a support channel, but that would be handy for those who are not familiar with NodeJS but expertise on the PHP part of the gateway. We built over 15 gateways with the classic way, and now we're forced to do the same interface on NodeJS as well, so if you could provide an example, that would be really appreciated.

I've understood that canMakePayment function can hold CartTotals variable, but what if i want to design an selectbox depending on the cart total on Content of the const Dummy, before sending it to registerPaymentMethod

@mikejolley
Copy link
Member

@seldimi there are examples in the resources I listed and in this repository

registerPaymentMethod( Dummy );

content is also provided with the context you require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants