I am trying to create a coupon click counter.
I received the default number of clicks using the code
<?php $couponusers = get_field('coupon_users'); ?>
And I displayed the default number of clicks using the code,
<p><?php echo $couponusers ?></p>
Now, I want to increase the value of ‘coupon_users’ whenever a click is made. Any suggestions on how to do this?
The page I need help with: https://deals.onlinerockershub.com/bluehost-web-hosting/
Add this action to your functions.php
function coupon_callback() {
//
// Add here cookie check
//
if(is_page('1')){ // ID of "Thank you for coupon click" page
update_field('coupon_users',$couponusers); // or similar
}
return;
}
add_filter( 'wp', 'coupon_callback' );
Good morning everyone, i have a problem with wordpress.
When I click add button I add the structure of an html page.
I would like to add this structure into a new div under the box add section.
Any ideas?
Thanks in advance
Edit 1:
Maybe I find a solution.
add_action('add_meta_boxes', 'add_custom_meta_box', 'post_type');
function add_custom_meta_box($post_type) {
global $post;
if ($post_type == 'minisites') {
add_meta_box('sections_meta_box', 'Add Section', 'show_custom_meta_box');
echo '<div id="htmlBox" class="postbox"></div>';
}
}
So, in this way I create a div when a meta box is created, after I set the content of this div with jQuery. Correct?
I'm trying to add a reCAPTCHA to WooCommerce Checkout on WordPress. When I use the following snippet the captcha loads and works correctly:
add_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_recaptcha_field' );
function woocommerce_checkout_recaptcha_field( ) {
echo '<div class="g-recaptcha" data-sitekey="XXXXXXXXXXXX"></div>';
}
However as soon as I move it next to the terms and conditions checkbox:
add_action( 'woocommerce_checkout_before_terms_and_conditions', 'woocommerce_checkout_recaptcha_field' );
function woocommerce_checkout_recaptcha_field( ) {
echo '<div class="g-recaptcha" data-sitekey="XXXXXXXXXXXX"></div>';
}
The captcha stops loading. I can see the captcha beginning to load as the page makes a gap for it but then after a split second it disappears again.
Anyone got any ideas?
Thanks
First, I'd like to pre-emptively apologize for doing anything naive or foolish. I'm a novice programmer, but I'm trying to learn. Right now, I'm trying to develop a plugin for wordpress as part of my internship. The plugin does what it needs to do for the most part, but I just can't seem to make the settings page work the way I want. I know the initialization part of the plugin is working properly, but I'm having trouble with using the settings page. Specifically, I don't where or how to use _POST in order to save the information. I also don't where to place the update_option function call after I've received the information from the settings page. Here's my code right now:
add_action( 'admin_menu', 'menu' );
add_action( 'admin_init', 'plugin_admin_init' );
function plugin_admin_init() { // whitelist options
register_setting( 'plugin_options', 'plugin_options', 'plugin_options_validate' );
add_settings_section('plugin_main', 'Main Settings', 'plugin_section_text', 'plugin');
add_settings_field('plugin_text_string', 'REE View Count Settings', 'plugin_setting_string', 'plugin', 'plugin_main');
}
function menu() {
add_options_page( 'REE View Count Options', 'REE View Count', 'manage_options', 'plugin', 'plugin_options_page' );
}
// generates the settings web page
function plugin_options_page() {
echo '<div class="wrap">';
echo '<h2>Options</h2>';
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
// In the line above, I don't know what to put. The file name of the plugin?
// The URL of the settings page on the admin page? Or what I have currently?
// Both the first and last options bring up a 404 page.
settings_fields('plugin_options');
do_settings_sections('plugin');
echo '<input name="Submit" type="submit" value="' . esc_attr_e('Save Changes') . '" />';
echo '</form>';
//update_option('plugin_options', $_POST['plugin_options']);
// Where should I try to update the option? And how?
echo '</div>';
}
//from add_settings_section parameter 3, in plugin_admin_init
function plugin_section_text() {
echo '<p>Main description of this section here.</p>';
}
//Function from 3 paramter of add_settings_field in plugin_admin_init that outputs input HTML
function plugin_setting_string() {
$options = get_option('plugin_options');
echo 'value of options is: ' . $options;
echo "<input id='plugin_text_string' name='plugin_options' size='40' type='text'
value='{$options}' />";
}
//Validation function from register_setting in plugin_admin_init
function plugin_options_validate($input) {
echo "this is input: " . $input;
$newinput = trim($input);
if(!preg_match('/^[0-9]+$/', $newinput)) {
$newinput = 10;
}
update_option('plugin_options', $newinput);
return $newinput;
}
Note: I don't actually use these exact function/variable names - I have them prefixed with the actual plugin name.
Can you help me? I want to take the information the admin inputs into the settings page and update the database with the that information (which in this case is just a single number). I understand that I need to use PHP _POST, but I don't know how. Furthermore, I don't where to post to, because when I use action="the_file_name.php," I get a 404 error upon submission. What should the action of the form be so that I can use the information that I got from the admin submission and use it for later? And after I do that, how do update the setting? And by how, I mean where do I place update_option? I apologize if this seems rambly or vague - I feel like I'm somewhat over my head.
If it helps, I've been building this settings page in the same file as the plugin itself, with the help of this guide: http://ottopress.com/2009/wordpress-settings-api-tutorial/
Unfortunately, I don't see anything in that guide that speaks of updating information, just creating the page itself.
You want to point to action="options.php". It handles updating the values. Check out the following links to get more detailed info.
http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
http://www.sitepoint.com/wordpress-options-panel/
I am using a custom field plugin for Wordpress so that users of the CMS can keep post items organized. I setup the fields and in my loop I display the like this..
<p><strong>Business Phone:</strong> <?php the_field('business_phone'); ?></p>
How would I hide or change the color of the title if there is no information entered into the field? I've gotten this far. Am I on the right track?
<?php
if ( get_group('business_phone',TRUE) ) {
echo 'I see a phone number!!';
} else {
echo 'I don\'t see a phone number!!';
}
?>
ok.. I'll check out the Wordpress forum.