Skip to content

Commit

Permalink
Support for WooCommerce cart and checkout blocks (#32)
Browse files Browse the repository at this point in the history
* Update wp and wc versions on docker.
* Adding blocks functionality, removing assets/js from git.
* make sure overPaid property exists before accessing.
  • Loading branch information
ndeet authored Dec 14, 2023
1 parent 134bd0e commit bda09dd
Show file tree
Hide file tree
Showing 19 changed files with 39,238 additions and 798 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ node_modules/
/vendor/
composer.lock
/generated/

/assets/js/
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM wordpress:6.1-php8.2
FROM wordpress:6.4-php8.2

ENV WOOCOMMERCE_VERSION 7.3.0
ENV WOOCOMMERCE_VERSION 8.4.0

# Fetch WooCommerce.
RUN apt-get update \
Expand Down
46 changes: 0 additions & 46 deletions Gruntfile.js

This file was deleted.

28 changes: 28 additions & 0 deletions bin/build_i18n.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Check for required version.
WPCLI_VERSION=`wp cli version | cut -f2 -d' '`
if [ ${WPCLI_VERSION:0:1} -lt "2" -o ${WPCLI_VERSION:0:1} -eq "2" -a ${WPCLI_VERSION:2:1} -lt "1" ]; then
echo WP-CLI version 2.1.0 or greater is required to make JSON translation files
exit
fi

# HELPERS.
GREEN='\033[0;32m'
GREY='\033[0;38m'
NC='\033[0m' # No Color
UNDERLINE_START='\e[4m'
UNDERLINE_STOP='\e[0m'

# Substitute JS source references with build references.
for T in `find languages -name "*.pot"`
do
echo -e "\n${GREY}${UNDERLINE_START}Fixing references for: ${T}${UNDERLINE_STOP}${NC}"
sed \
-e 's/ resources\/js\/frontend\/[^:]*:/ assets\/frontend\/blocks.js:/gp' \
$T | uniq > $T-build

rm $T
mv $T-build $T
echo -e "${GREEN}Done${NC}"
done
27 changes: 22 additions & 5 deletions btcpay-greenfield-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* Author URI: https://btcpayserver.org
* Text Domain: btcpay-greenfield-for-woocommerce
* Domain Path: /languages
* Version: 2.3.0
* Version: 2.4.0
* Requires PHP: 7.4
* Tested up to: 6.3
* Tested up to: 6.4
* Requires at least: 5.2
* WC requires at least: 6.0
* WC tested up to: 8.0
* WC tested up to: 8.4
*/

use BTCPayServer\WC\Admin\Notice;
Expand All @@ -26,7 +26,7 @@

defined( 'ABSPATH' ) || exit();

define( 'BTCPAYSERVER_VERSION', '2.3.1' );
define( 'BTCPAYSERVER_VERSION', '2.4.0' );
define( 'BTCPAYSERVER_VERSION_KEY', 'btcpay_gf_version' );
define( 'BTCPAYSERVER_PLUGIN_FILE_PATH', plugin_dir_path( __FILE__ ) );
define( 'BTCPAYSERVER_PLUGIN_URL', plugin_dir_url(__FILE__ ) );
Expand Down Expand Up @@ -270,6 +270,20 @@ public static function orderStatusThankYouPage($order_id)
";
}

/**
* Register WooCommerce Blocks support.
*/
public static function blocksSupport() {
if ( class_exists( '\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register(new \BTCPayServer\WC\Blocks\DefaultGatewayBlocks());
}
);
}
}

/**
* Gets the main plugin loader instance.
*
Expand Down Expand Up @@ -303,7 +317,6 @@ function init_btcpay_greenfield() {
flush_rewrite_rules(false);
update_option('btcpaygf_permalinks_flushed', 1);
}

});

// Action links on plugin overview.
Expand Down Expand Up @@ -426,5 +439,9 @@ function init_btcpay_greenfield() {
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
}
} );

// Register WooCommerce Blocks integration.
add_action( 'woocommerce_blocks_loaded', [ 'BTCPayServerWCPlugin', 'blocksSupport' ] );
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
restart: no
environment:
MYSQL_ROOT_PASSWORD: rootpress
MYSQL_DATABASE: wordpress
Expand All @@ -21,7 +21,7 @@ services:
- ./:/var/www/html/wp-content/plugins/btcpay-greenfield-for-woocommerce
ports:
- "8821:80"
restart: always
restart: no
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
Expand Down
Loading

0 comments on commit bda09dd

Please sign in to comment.