Merge pull request #2477 from woocommerce/PCP-3492-static-meta-comment-in-html-source-when-fastlane-is-active

Static meta comment in HTML source when Fastlane is active (3492)
This commit is contained in:
Danny Dudzic 2024-08-01 19:22:04 +02:00 committed by GitHub
commit 932b86ad1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -194,9 +194,17 @@ class AxoModule implements ModuleInterface {
add_action(
'wp_head',
function () {
function () use ( $c ) {
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
echo '<script async src="https://www.paypalobjects.com/insights/v1/paypal-insights.sandbox.min.js"></script>';
// Add meta tag to allow feature-detection of the site's AXO payment state.
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
$this->add_feature_detection_tag(
$settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' )
);
}
);
@ -396,4 +404,23 @@ class AxoModule implements ModuleInterface {
// Exclude the Order Pay endpoint.
return is_wc_endpoint_url( 'order-pay' );
}
/**
* Outputs a meta tag to allow feature detection on certain pages.
*
* @param bool $axo_enabled Whether the gateway is enabled.
* @return void
*/
private function add_feature_detection_tag( bool $axo_enabled ) {
$show_tag = is_checkout() || is_cart() || is_shop();
if ( ! $show_tag ) {
return;
}
printf(
'<meta name="ppcp.axo" content="%s" />',
$axo_enabled ? 'enabled' : 'disabled'
);
}
}