Skip to content

Commit

Permalink
Merge pull request #240 from TycheSoftwares/Fix-#237
Browse files Browse the repository at this point in the history
Fix #237 fees not showing on block checkout
  • Loading branch information
mokshasharmila13 authored Jul 5, 2024
2 parents 3a5d1d0 + d423b2a commit 4f112e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 81 deletions.
33 changes: 0 additions & 33 deletions build/checkout-block-frontend.js

This file was deleted.

2 changes: 1 addition & 1 deletion build/checkout-fees-for-woocommerce.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wc-blocks-checkout', 'wp-element', 'wp-i18n'), 'version' => '7b2d759ead81217562b8');
<?php return array('dependencies' => array(), 'version' => '809990fb9b3428ea2e63');
2 changes: 1 addition & 1 deletion build/checkout-fees-for-woocommerce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 13 additions & 46 deletions src/frontend.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
import metadata from './block.json';
import { ValidatedTextInput } from '@woocommerce/blocks-checkout';
import { __ } from '@wordpress/i18n';
import { useEffect, useState, useCallback } from '@wordpress/element';
import { extensionCartUpdate } from '@woocommerce/blocks-checkout';

// Global import
const { registerCheckoutBlock } = wc.blocksCheckout;

const Block = ({ children, checkoutExtensionData }) => {
const { setExtensionData } = checkoutExtensionData;

useEffect( () => {

wp.hooks.addAction( 'experimental__woocommerce_blocks-checkout-set-active-payment-method', 'checkout-block-example', function( payment_method ) {
var update_cart = extensionCartUpdate( {
namespace: 'checkout-fees-for-woocommerce',
data: {
payment_method: payment_method.value,
},
});
const { PAYMENT_STORE_KEY } = window.wc.wcBlocksData; // "wc/store/payment"
const { extensionCartUpdate } = window.wc.blocksCheckout;
const { subscribe, select } = wp.data;
let previouslyChosenPaymentMethod = '';

subscribe( function () {
const chosenPaymentMethod = select( PAYMENT_STORE_KEY ).getActivePaymentMethod();
extensionCartUpdate( {
namespace: 'checkout-fees-for-woocommerce',
data: {
payment_method: chosenPaymentMethod,
},
} );

wp.hooks.addAction( 'experimental__woocommerce_blocks-checkout-set-selected-shipping-rate', 'checkout-block-example', function( shipping ) {
var update_cart = extensionCartUpdate( {
namespace: 'checkout-fees-for-woocommerce',
data: {
payment_method: shipping.storeCart.paymentMethods[0],
},
});
} );

}, [] );

const onInputChange = useCallback(
( value ) => {
},
[ setGiftMessage. setExtensionData ]
)
}

const options = {
metadata,
component: Block
};

registerCheckoutBlock( options );
}, PAYMENT_STORE_KEY );

0 comments on commit 4f112e8

Please sign in to comment.