I am having trouble to keep the state of Wordpress Widget option checkbox. Here is my code
<label for="<?php echo $this->get_field_id('display_name'); ?>"><input
type="checkbox"
id="<?php echo $this->get_field_id('display_name'); ?>"
name="<?php echo $this->get_field_name('display_name'); ?>"
<?php checked(isset($display_name) ? $display_name : 0); ?> /> Display name</label>
Also I want to know how can I use multiple checkbox group to store and retrieve data
Okay found the easy solution
Instead of $display_name in checked I simply changed to 1 and it works :)
Before:
<?php checked(isset($display_name) ? $display_name : 0); ?>
After:
<?php checked(isset($display_name) ? 1 : 0); ?>
I don't know why but this answer did not work for me, after reviewing the checked() documentation I tried to follow some of those example with no luck. So eventually I resulted to this simple snippet (just plain php) and it worked as expected.
<?php echo $checked = ($display_name=== "on") ? "checked" : ""; ?>
Related
I want to add a separate payment button for each payment method in WooCommerce.I designed checkout page using cart flows
I tried in chrome developers tool by copying button html content and place in every div of payment methods
but that was just temporarily changes..
I then go to plugin files editor and select cart flows plugin but don't know what's to do next
You should consider modifying the template files..
Locate the WooCommerce template files:
You can find the template files in the
"wp-content/plugins/woocommerce/templates" directory.
Copy the "checkout/payment.php" file:
Make a backup of the original file and then copy the "payment.php"
file to your theme directory.
Edit the copied file:
In the copied file, look for the section that displays the payment
methods and modify it to add separate buttons for each payment method.
Example code (That's an old woocommerce version I found in my computer and edited it) :
<input type="radio" id="payment_method_<?php echo esc_attr( $gateway->id ); ?>" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> />
<label for="payment_method_<?php echo esc_attr( $gateway->id ); ?>">
<?php echo wp_kses_post( $gateway->get_title() ); ?> <?php echo wp_kses_post( $gateway->get_icon() ); ?>
</label>
<div class="payment_box payment_method_<?php echo esc_attr( $gateway->id ); ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>>
<?php $gateway->payment_fields(); ?>
</div>
Save and upload the file:
Save the changes and upload the edited file to your theme directory.
I have been taking what I thought would be a simple HTML code. I tried to follow this tutorial here:
However, I am not able to get a simple input field to be added to the bottom of any widget. Could someone please tell me what I am missing?
After add below to my functions file, below does not output HTML of any thing withing wp-admin/widgets.php. Help please!
function thmfdn_add_menu_description_option( $widget, $return, $instance ) {
// Are we dealing with a nav menu widget?
if ( 'nav_menu' == $widget->id_base ) {
// Display the description option.
$description = isset( $instance['description'] ) ? $instance['description'] : '';
?>
<p>
<input class="checkbox" type="checkbox" id="<?php echo $widget->get_field_id('description'); ?>" name="<?php echo $widget->get_field_name('description'); ?>" <?php checked( true , $description ); ?> />
<label for="<?php echo $widget->get_field_id('description'); ?>">
<?php _e( 'Show descriptions', 'thmfdn_textdomain' ); ?>
</label>
</p>
<?php
}
}
add_action('in_widget_form', 'thmfdn_add_menu_description_option', 10, 3 );
My goal is to add visibility controls to widgets in order to dynamically display or high them on the frontend based on user logged in or not. To achieve that I want to extend existing widgets by adding extra settings that sets whether a widget should be rendered on frontend based on user status.
Thank you for any correction or solutions.
how to use this function correctly:
<?php echo do_shortcode('[product id="<?php the_field('wyrozniony_produkt_id')?>"]'); ?>
I need write inside this in place 3931
<?php echo do_shortcode('[product id="3931"]'); ?>
This shortcode (textfield from ACF)
<?php the_field('wyrozniony_produkt_id')?>
Anyone have idea how to make this?
your syntax seems to be wrong
please check the updated code of yours
<?php
$product_id = get_field('wyrozniony_produkt_id');
echo do_shortcode('[product id="'.$product_id.'"]');
?>
I have created custom meta box using WPAlchemy class to add option for related posts.
Following code is working file in WP-Admin, and also in frontend only if i add related posts to the custom form created with meta box.
However if i leave this empty, i am getting following warning message
Warning: Illegal string offset 'topics' in
/homepages/9/d416241127/htdocs/tw/u2me/wp-content/themes/u2me/single.php
on line 37
Here line 37 is if ($my_meta['topics']) {
in other words i am getting warning message when this condition should return false.
I have used following code to create custom meta:
<?php while($mb->have_fields_and_multi('topics')): ?>
<?php $mb->the_group_open(); ?>
<?php $mb->the_field('title'); ?>
<label>Title</label>
<p style="margin-top:0px;"><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>
<?php $mb->the_field('link'); ?>
<label>URL</label>
<p style="margin-top:0px;"><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>
<p>Remove Topic</p>
<br/>
<?php $mb->the_group_close(); ?>
<?php endwhile; ?>
and used following code in single.php to show the values stored using above code:
<?php
$my_meta = get_post_meta($post->ID,'_related_topics_meta',TRUE);
if ($my_meta['topics']) {
echo '<ul class="hero-subtitle">';
foreach ($my_meta['topics'] as $topic) {
?>
<li><?php echo $topic['title']; ?></li>
<?php }
echo '</ul>';
} ?>
use
if ($my_meta['topics']) {
AS
if (!empty($my_meta['topics'])) {
may be this will help you
I am in the works of throwing together what I believe to be a fairly simple widget for a client site, but being my second Widget ever I still have quite a bit of a learning curve to overcome.
The Story
In this particular project I have attempted to create some textarea inputs to output into some simple paragraph tags. But I kinda tackled it as logically as I could but I am sure it is pretty gross code as I am not a PHP expert by even the leanest standards.
The Issue
My issue is that I wish to have my textarea's output with auto paragraphing. Such as the default text widget wordpress provides when the checkbox is checked. Also maybe just have a look over at how I even created the textarea's. I am sure there is a better practice then what I put together.
Textarea Sample
<p>
<label for="<?php echo $this->get_field_id( 'admitted' ); ?>"><?php _e('Admitted to Practice', 'framework') ?></label>
<textarea class="widefat" id="<?php echo $this->get_field_id( 'admitted' ); ?>" name="<?php echo $this->get_field_name( 'admitted' ); ?>" value="<?php echo $this->get_field_name( 'admitted' ); ?>" /><?php echo $instance['admitted']; ?></textarea>
</p>
I don't know if maybe putting tinymce on them would help solve this or not (not that I know how to do that) But I am wide open to suggestions.
Take a look at the full code here.
Dropbox Zip of Widget
You know that you can easily look at how the default widgets are built, right? Just go to wp-includes/default-widgets.php
If I understand your issue correctly you are looking for this piece of code in the class WP_Widget_Text in that file,
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
As you can see, it is the wpautop function that does the trick.
I think the way you created your form is fine. If you want to learn best practices, again, Wordpress source code is useful.
I was able to accomplish this using the code below.
<p><strong>Admitted to Practice:</strong><br/><?php echo wpautop($this->admitted_practice); ?></p>
Thank you Calle for your response.