Skip to content

Instantly share code, notes, and snippets.

@dechov

dechov/cors.php Secret

Last active June 28, 2021 00:54
Show Gist options
  • Save dechov/4f1cf38e4e5ae7129dc7a8ab3c55373c to your computer and use it in GitHub Desktop.
Save dechov/4f1cf38e4e5ae7129dc7a8ab3c55373c to your computer and use it in GitHub Desktop.
<?php
// Derived from https://github.com/senadir/helper-headless-plugin/blob/trunk/includes/cors.php
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Origin: ' . 'https://headless-woocommerce-dechov.vercel.app' );
header( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTION' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, X-WC-Store-API-Nonce' );
header( 'Access-Control-Expose-Headers: X-WC-Store-API-Nonce, X-WC-Store-API-Nonce-Timestamp');
return $value;
} );
add_filter( 'allowed_http_origins', function( $allowed_origins ) {
header( 'Access-Control-Allow-Headers: content-type, x-wc-store-api-nonce' );
$allowed_origins[] = 'https://headless-woocommerce-dechov.vercel.app';
return $allowed_origins;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment