Created
August 29, 2015 14:59
-
-
Save WPprodigy/96dbaeab8820cc85af42 to your computer and use it in GitHub Desktop.
Example of how you can add a settings fields, and retrieve the value in the shortcode template.
This file contains 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 | |
/** | |
* Add Product Settings Section to the Admin | |
*/ | |
add_action( 'wcepe_after_transients_settings', 'wcepe_custom_settings_section' ); | |
function wcepe_custom_settings_section() { | |
// Transient Section | |
add_settings_section( | |
'wcepe_products_settings_section', | |
__( 'Product Settings', 'woocommerce-external-product-embed' ), | |
'wcepe_product_settings_instructions','wcepe_settings_group' | |
); | |
// Consumer Secret | |
add_settings_field( | |
'wcepe_extra_button', | |
__( 'Extra Button Link', 'woocommerce-external-product-embed' ), | |
'wcepe_product_settings_text_field', 'wcepe_settings_group', 'wcepe_products_settings_section' | |
); | |
} | |
function wcepe_product_settings_instructions() { | |
echo "Configure the Product Settings"; | |
} | |
function wcepe_product_settings_text_field() { | |
$options = get_option( 'wcepe_settings' ); ?> | |
<input type='text' class="regular-text wcepe_extra_button" name='wcepe_settings[wcepe_extra_button]' value='<?php echo $options['wcepe_extra_button']; ?>'> | |
<?php | |
} | |
// End Admin Settings | |
/** | |
* Add Extra Button front-end product array | |
*/ | |
add_filter( 'wcepe_filter_product', 'wcepe_add_extra_button' ); | |
function wcepe_add_extra_button( $product ) { | |
$product['extra_button'] = 'testing'; | |
return $product; | |
} | |
// End Front-End Settings | |
/** | |
* Add the following line of code wherever you would like to in the template to show this contents of this newly created field: | |
* | |
* <a href=<?php echo $product['extra_button'] ?> class="" target="_blank"><?php echo "Visit Store" ?></a> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results
Settings: http://cld.wthms.co/1achx/4CLyaJMO
Front-end: http://cld.wthms.co/1eAvT/2YDynWSS