| @@ -1043,12 +1043,30 @@ | ||
| 1043 | 1043 | |
| 1044 | 1044 | public function get_html_button_attrs_for_context($context = 'global') { |
| 1045 | 1045 | $options = get_option('vipps_button_options2', []); |
| 1046 | 1046 | if (!is_string($context)) $context = 'global'; |
| 1047 | + | |
| 1048 | + // Gutenberg express checkout buttons really want to be stretched, so we'll treat them somewhat differently. | |
| 1049 | + $gutenberg = false; | |
| 1050 | + if ($context == 'checkout_gutenberg') { | |
| 1051 | + $context = 'checkout'; | |
| 1052 | + $gutenberg = true; | |
| 1053 | + } | |
| 1054 | + if ($context == 'cart_gutenberg') { | |
| 1055 | + $context = 'cart'; | |
| 1056 | + $gutenberg = true; | |
| 1057 | + } | |
| 1058 | + | |
| 1047 | 1059 | $config = $options['express']['configs'][$context] ?? []; |
| 1048 | - if (!$config || ($config['use-global-config'] ?? false)) { | |
| 1060 | + $use_global = !$config || ($config['use-global-config'] ?? false); | |
| 1061 | + if ($use_global) { | |
| 1049 | 1062 | $config = $options['express']['configs']['global'] ?? $this->get_html_button_default_attrs(); |
| 1050 | 1063 | } |
| 1064 | + | |
| 1065 | + // see above. | |
| 1066 | + if ($gutenberg) { | |
| 1067 | + $config['stretched']='true'; | |
| 1068 | + } | |
| 1051 | 1069 | return $config; |
| 1052 | 1070 | } |
| 1053 | 1071 | |
| 1054 | 1072 | public function get_html_button_for_context($context = 'global') { |
| @@ -1135,8 +1153,10 @@ | ||
| 1135 | 1153 | private function button_menu_express_section() { |
| 1136 | 1154 | $options = get_option('vipps_button_options2', []); |
| 1137 | 1155 | $express = $options['express'] ?? []; |
| 1138 | 1156 | $configs = $express['configs'] ?? []; |
| 1157 | + | |
| 1158 | + | |
| 1139 | 1159 | $contexts = [ |
| 1140 | 1160 | 'global' => __('Global', 'woo-vipps'), |
| 1141 | 1161 | 'product' => __('Product', 'woo-vipps'), |
| 1142 | 1162 | 'catalog' => __('Catalog', 'woo-vipps'), |
| @@ -1309,8 +1329,9 @@ | ||
| 1309 | 1329 | |
| 1310 | 1330 | // Swap to new context: set all input fields to the stored values if exists. LP 2026-06-25 |
| 1311 | 1331 | const newContext = jQuery("#context").val(); |
| 1312 | 1332 | const newConfig = contextConfigs[newContext]; |
| 1333 | + | |
| 1313 | 1334 | setInputsFromConfig(newContext, newConfig); |
| 1314 | 1335 | currentContext = newContext; |
| 1315 | 1336 | } |
| 1316 | 1337 | |
| @@ -1911,16 +1932,15 @@ | ||
| 1911 | 1932 | public function minicart_express_checkout_button() { |
| 1912 | 1933 | $gw = $this->gateway(); |
| 1913 | 1934 | |
| 1914 | 1935 | if ($gw->show_express_checkout()){ |
| 1915 | - return $this->cart_express_checkout_button_html(true); | |
| 1936 | + return $this->cart_express_checkout_button_html('minicart'); | |
| 1916 | 1937 | } |
| 1917 | 1938 | } |
| 1918 | 1939 | |
| 1919 | - public function cart_express_checkout_button_html($minicart = false) { | |
| 1940 | + public function cart_express_checkout_button_html($context= 'cart') { | |
| 1920 | 1941 | $url = $this->express_checkout_url(); |
| 1921 | 1942 | $url = wp_nonce_url($url,'express','sec'); |
| 1922 | - $context = $minicart ? 'minicart' : 'cart'; | |
| 1923 | 1943 | $button= apply_filters('woo_vipps_express_checkout_button', $this->get_html_button_for_context($context)); |
| 1924 | 1944 | $method = $this->get_payment_method_name(); |
| 1925 | 1945 | $title = sprintf(__('Buy now with %1$s!', 'woo-vipps'), $method); |
| 1926 | 1946 | $html = "<a href='$url' class='vipps-express-checkout short $method' title='$title'>$button</a>"; |
| @@ -1963,9 +1983,9 @@ | ||
| 1963 | 1983 | public function express_checkout_button_shortcode() { |
| 1964 | 1984 | $gw = $this->gateway(); |
| 1965 | 1985 | if (!$gw->cart_supports_express_checkout()) return; |
| 1966 | 1986 | ob_start(); |
| 1967 | - $this->cart_express_checkout_button_html('shortcode'); | |
| 1987 | + $this->cart_express_checkout_button_html('cart'); | |
| 1968 | 1988 | return ob_get_clean(); |
| 1969 | 1989 | } |
| 1970 | 1990 | // Show a banner normally shown for non-logged-in-users at the checkout page. It does not need to check if we are to show the button, obviously, but needs to see if the cart works |
| 1971 | 1991 | public function express_checkout_banner_shortcode() { |
| @@ -4148,9 +4168,9 @@ | ||
| 4148 | 4168 | WC()->cart->calculate_totals(); |
| 4149 | 4169 | WC()->cart->set_session(); |
| 4150 | 4170 | return true; |
| 4151 | 4171 | } catch (Exception $e) { |
| 4152 | - $this->log(sprintf(__("Error regenerating cart from order %1\$d: %2\$s", 'woo-vipps'), $order_id, $e->get_message()), 'error'); | |
| 4172 | + $this->log(sprintf(__("Error regenerating cart from order %1\$d: %2\$s", 'woo-vipps'), $order_id, $e->getMessage()), 'error'); | |
| 4153 | 4173 | return false; |
| 4154 | 4174 | } |
| 4155 | 4175 | } |
| 4156 | 4176 | |