Last active
February 18, 2020 18:08
-
-
Save paulmiller3000/390b8a7885a10efd36f3a56085948e25 to your computer and use it in GitHub Desktop.
Register Advanced Custom Fields for WooCommerce with the WordPress API
This file contains hidden or 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
<?php | |
/* | |
* Register ACF fields to WordPress API | |
* Tutorial: https://battlestardigital.com/wp-admin/post.php?post=2838&action=edit | |
*/ | |
add_action( 'rest_api_init', 'bsd_register_acf_with_api' ); | |
function bsd_register_acf_with_api() { | |
if (!function_exists('get_fields')) return; | |
register_rest_field( | |
'product', | |
'acf', | |
array( | |
'get_callback' => 'bsd_add_acf_fields', | |
) | |
); | |
} | |
function bsd_add_acf_fields( $object, $field_name, $request ) { | |
$acf = get_fields( $object['id'] ); | |
return $acf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment