PluginProbe
Pay with Vipps and MobilePay for WooCommerce / trunk
Pay with Vipps and MobilePay for WooCommerce vtrunk
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 All 187 releases
woo-vipps / payment / Blocks / dist / buy-now / render.php

render.php in Pay with Vipps and MobilePay for WooCommerce trunk, at payment/Blocks/dist/buy-now/render.php

38 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $vipps = Vipps::instance();
3 $supported = false;
4
5 // hasProductContext is set if we are in a product template parent block context. LP 2026-01-19
6 if ($block->attributes['hasProductContext']) {
7 $pid = $block->context['postId'] ?? 0;
8 $product = $pid ? wc_get_product($pid) : 0;
9 if ($product && is_a($product, 'WC_Product')) {
10 $supported = $vipps->loop_single_product_is_express_checkout_purchasable($product);
11 }
12 }
13
14 // else we need to get product from the block config. LP 2026-01-19
15 else {
16 $pid = $block->attributes['productId'] ?? 0;
17 $product = $pid ? wc_get_product($pid) : 0;
18 if ($product && is_a($product, 'WC_Product')) {
19 $supported = $vipps->loop_single_product_is_express_checkout_purchasable($product);
20 }
21 }
22
23 // Only create button if the product has woo-vipps express checkout enabled. LP 29.11.2024
24 if ($supported) {
25 // In retrospect, the web component button args should probably be in one attribute object instead, to avoid stuff like this. LP 2026-07-01
26 $button_args = [];
27 foreach(['compact', 'rounded'] as $bool_attr) {
28 $button_args[$bool_attr] = ($block->attributes[$bool_attr] ?? false) ? 'true' : 'false';
29 }
30 foreach(['verb', 'variant', 'language'] as $str_attr) {
31 $button_args[$str_attr] = $block->attributes[$str_attr] ?? '';
32 }
33 // Looks like button and badge web components now use 'da' instead of 'dk' for danish. LP 2026-08-11
34 if ('dk' === $button_args['language']) $button_args['language'] = 'da';
35
36 echo "<div class='wp-block-button wc-block-components-product-button wc-block-button-vipps'>" . $vipps->get_buy_now_button($product->get_id(), null, null, false, '', 'gutenberg', $button_args) . "</div>";
37 }
38