-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
5,293 additions
and
5,718 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "woo-vipps/buy-now", | ||
"version": "2.0.0", | ||
"title": "Vipps MobilePay Buy Now", | ||
"attributes": { | ||
"isInQuery": { | ||
"type": "boolean", | ||
"default": "false" | ||
} | ||
}, | ||
"keywords": [ | ||
"WooCommerce", | ||
"woo-gutenberg-products-block" | ||
], | ||
"category": "woocommerce", | ||
"parent": [ | ||
"woocommerce/product-template" | ||
], | ||
"usesContext": [ | ||
"query", | ||
"queryId", | ||
"postId" | ||
], | ||
"supports": { | ||
"html": false | ||
}, | ||
"textdomain": "woo-vipps", | ||
"editorScript": "file:./index.js", | ||
"render": "file:./render.php" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks'), 'version' => 'ff77120c8b85614bd344'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
$vipps = Vipps::instance(); | ||
$supports = false; | ||
$pid = $block->context['postId'] ?? 0; | ||
$product = $pid ? wc_get_product($pid) : 0; | ||
if ($product && is_a($product, 'WC_Product')) { | ||
$supports = $vipps->loop_single_product_is_express_checkout_purchasable($product); | ||
|
||
} | ||
|
||
// Only create button if the product has woo-vipps express checkout enabled. LP 29.11.2024 | ||
if ($supports) { | ||
echo "<div class='wp-block-button wc-block-components-product-button wc-block-button-vipps'>" . $vipps->get_buy_now_button($product->get_id(), false) . "</div>"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => 'a24a031dce25d8203fb0'); | ||
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => '0a1d868840342b2070f3'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
<?php | ||
|
||
// This is the new script to register blocks built into ./dist. At this time only the vipps-badge block. LP 19.11.2024 | ||
// This is the script to register blocks built into ./dist. LP 19.11.2024 | ||
|
||
// Register blocks | ||
add_action('init', function () { | ||
register_block_type(__DIR__ . '/dist/vipps-badge'); | ||
// vipps-badge block. LP 29.11.2025 | ||
register_block_type(__DIR__ . '/dist/vipps-badge'); | ||
|
||
// Buy-now product block uses JS event introduced in woocommerce 9.4. LP 29.11.2024 | ||
if (version_compare(WC_VERSION, '9.4', '>=')) { | ||
register_block_type(__DIR__ . '/dist/buy-now'); | ||
|
||
} | ||
}); | ||
|
||
// Inject block config variables to vipps-badge editor script. LP 15.11.2024 | ||
// Inject block config variables to block editor assets | ||
add_action('enqueue_block_editor_assets', function () { | ||
$vipps = Vipps::instance(); | ||
$variants = $variants = [ | ||
// vipps-badge config | ||
$vipps = Vipps::instance(); | ||
$variants = $variants = [ | ||
['label' => __('White', 'woo-vipps'), 'value' => 'white'], | ||
['label' => __('Grey', 'woo-vipps'), 'value' => 'grey'], | ||
['label' => __('Filled', 'woo-vipps'), 'value' => 'filled'], | ||
['label' => __('Light', 'woo-vipps'), 'value' => 'light'], | ||
['label' => __('Purple', 'woo-vipps'), 'value' => 'purple']]; | ||
|
||
// Set a default language for the vipps-badge. LP 21.11.2024 | ||
$store_language = substr(get_bloginfo('language'), 0, 2); | ||
if ($store_language == 'nb' || $store_language == 'nn') { | ||
// Set a default language for the vipps-badge. LP 21.11.2024 | ||
$store_language = substr(get_bloginfo('language'), 0, 2); | ||
if ($store_language == 'nb' || $store_language == 'nn') { | ||
$store_language = 'no'; | ||
} | ||
if ($store_language == 'da') { | ||
} | ||
if ($store_language == 'da') { | ||
$store_language = 'dk'; | ||
} | ||
if (!in_array($store_language, ['en', 'no', 'dk', 'fi'])) { | ||
$store_language = 'en'; | ||
} // english default fallback | ||
|
||
$block_config = [ | ||
'title' => sprintf(__('%1$s On-Site Messaging Badge', 'woo-vipps'), Vipps::CompanyName()), | ||
'variants' => $variants, | ||
'defaultVariant' => 'white', | ||
'defaultLanguage' => $store_language, | ||
'iconSrc' => plugins_url('../img/vipps-mobilepay-logo-only.png', __FILE__), | ||
'brand' => strtolower($vipps->get_payment_method_name()), | ||
'languages' => [ | ||
['label' => __('Default', 'woo-vipps'), 'value' => $store_language], | ||
['label' => __('English', 'woo-vipps'), 'value' => 'en'], | ||
['label' => __('Norwegian', 'woo-vipps'), 'value' => 'no'], | ||
['label' => __('Finnish', 'woo-vipps'), 'value' => 'fi'], | ||
['label' => __('Danish', 'woo-vipps'), 'value' => 'dk'], | ||
], | ||
]; | ||
|
||
wp_add_inline_script('woo-vipps-vipps-badge-editor-script', | ||
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config), | ||
'before'); | ||
}); | ||
} | ||
if (!in_array($store_language, ['en', 'no', 'dk', 'fi'])) { | ||
$store_language = 'en'; // english default fallback | ||
} | ||
|
||
$block_config = [ | ||
'title' => sprintf(__('%1$s On-Site Messaging Badge', 'woo-vipps'), Vipps::CompanyName()), | ||
'variants' => $variants, | ||
'defaultVariant' => 'white', | ||
'defaultLanguage' => $store_language, | ||
'iconSrc' => plugins_url('../img/vipps-mobilepay-logo-only.png', __FILE__), | ||
'brand' => strtolower($vipps->get_payment_method_name()), | ||
'languages' => [ | ||
['label' => __('Default', 'woo-vipps'), 'value' => $store_language], | ||
['label' => __('English', 'woo-vipps'), 'value' => 'en'], | ||
['label' => __('Norwegian', 'woo-vipps'), 'value' => 'no'], | ||
['label' => __('Finnish', 'woo-vipps'), 'value' => 'fi'], | ||
['label' => __('Danish', 'woo-vipps'), 'value' => 'dk'], | ||
], | ||
]; | ||
// vipps-badge config stop | ||
|
||
// Inject block config to vipps-badge editor script. LP 15.11.2024 | ||
wp_add_inline_script('woo-vipps-vipps-badge-editor-script', | ||
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config), | ||
'before'); | ||
|
||
// Inject config from Vipps.class.php to buy-now editor script. LP 29.11.2024 | ||
if (version_compare(WC_VERSION, '9.4', '>=')) { | ||
wp_add_inline_script('woo-vipps-buy-now-editor-script', 'const VippsConfig = ' . json_encode(Vipps::instance()->vippsJSConfig), 'before'); | ||
} | ||
}); |
Oops, something went wrong.