I want to add default image options in WordPress admin (we can say set default options in image field ) when I try to create an image field using ACF thank you so much in advance
You can put the code like below in your functions.php
add_action('acf/render_field_settings/type=image', 'add_defult_image_field');
function add_defult_image_field($field) {
acf_render_field_setting( $field, array(
'label' => 'Defult Image',
'instructions' => 'Appears when creating a new post',
'type' => 'image',
'name' => 'defult_value',
));
}
Taken from https://stupop010.medium.com/how-to-set-a-default-image-on-acf-wordpress-977d38869b78, you need to create an action to a default_value field. After that, add a filter that checks when the user did not select any image, and then loads the default value.
add_action('acf/render_field_settings/type=image', function ($field) {
acf_render_field_setting( $field, array(
'label' => __('Default Image','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'image',
'name' => 'default_value',
));
});
add_filter('acf/load_value/type=image', function ($value, $post_id, $field) {
if (!$value) {
$value = $field['default_value'];
}
return $value;
}, 10, 3);
Related
can you help me how this field is made.
I think you need new custom field on the checkout page. So, you can use this plugin: https://wordpress.org/plugins/woo-checkout-regsiter-field-editor/
Also, you can add this field manually:
add_action('woocommerce_before_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field ($checkout ) {
echo '<div id="customise_checkout_field">';
woocommerce_form_field('customised_field_name', array(
'type' => 'text',
'class' => array( 'my-field-class form-row-wide' ),
'label' => __('Customise Additional Field'),
'placeholder' => __('Guidence'),
'required' => true,
), $checkout->get_value('customised_field_name'));
echo '</div>';
}
Ofcourse, you need to modify this code for yourself, for example you can change action point from 'woocommerce_before_order_notes' to some other to move the field.
Im trying to echo a $var in a function array in WP. I need to have a field on the Woocommerce checkout (accomplished) with a VALUE from a $_SESSION. The checkout field looks like this:
// Our hooked in function - $fields is passed via the filter!
public function VAT_override_checkout_fields( $fields ) {
$fields['billing']['VAT_cui'] = array(
'label' => __('Domæne', 'woocommerce'),
'placeholder' => _x('Intet Valgt', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
'type' => 'select',
'options' => array(
'kobdomain' => __('echo $MYVAR', 'woocommerce' ),
)
);
return $fields;
}
I understand i doesnt work, but im stuck :(
Problem is i need the return $fields input value to be filled with a string from my Session. I think its possible with the SELECT OPTION field, but as you can see, i dunno how to echo value in it.
I'm attempting to add a conditionally displayed fieldset in a custom checkout pane. The fieldset is always displayed regardless of the state, unlike on a standard form.
For example, in the code below I want the "hungry_fields" fieldset displayed based on the value of the "hungry" radio button.
function hungry_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
$pane_form['hungry'] = array(
'#type' => 'radios',
'#options' => array('yes' => t('Yes'), 'no' => t('No')),
'#required' => TRUE,
'#title' => t('I am hungry')
);
$pane_form['hungry_fields'] = array(
'#title' => 'Hungry',
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#states' => array(
'visible' => array(
':input[name="hungry"]' => array('value' => 'yes'),
),
),
);
return $pane_form;
}
I'm new to Drupal Commerce so it's entirely possible I'm missing something.
I fixed this by using a form callback with drupal_get_form() instead of adding the fields to the array directly.
For example:
function hungry_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
$pane_form['form'] = drupal_get_form('hungry_form');
}
function hungry_form($form, &$form_state) {
...
}
Using this method the forms work properly.
I have a page.tpl.php in which has header , footer and content area. I need to load different content base on hook_menu from a module.
I am using the following test code in the module to try and print something from my template:
function my_module_theme() {
return array(
'tutorials_test' => array(
'template' => 'tutorial'
)
);
}
I have a template tutorial.tpl.php in the modules folder
The following is my hook_menu and the callback function
function my_module_menu() {
$items['insights/tutorials'] = array(
'title' => 'Tutorials',
'access callback' => TRUE,
'page callback' => 'insights_tutorials'
);
}
The callback function
function insights_tutorials() {
echo 'test';
print theme('tutorials_test');
echo 'after test';
}
When I turn to that page i can see the text 'test' and 'after test' but nothing from my template is printed.
tutorial.tpl.php has this simple code:
<h1>Hello World</h1>
Inside your hook_theme implementation (the function my_module_theme) you need to pass in the variables key
function my_module_theme() {
return array(
'tutorials_test' => array(
'template' => 'tutorial',
'variables' => array( // the variables key
'title' => NULL,
'details' => NULL,
),
)
);
}
Then output your HTML like that:
print theme('tutorials_test', array(
'title' => 'This is the title',
'details' => 'And this is details',
));
For a bitter example about how to implement hook_theme(), take a look at this answer.
Hope this works... Muhammad.
I am looking for a method to have a Admin-bar custom link open in a popup.
The code I have is as follows:
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'custom_link',
'title' => __('My custom link'),
'href' => 'http://www.google.com'
) );
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
Which results in:
It is still unclear to me however how I can have this specific link open (ideally) as a JavaScript popup or eventually in a new window.
Some advice would be very much appreciated.
Thank you very much,
Patrick
By adding meta information to your code will open the link in a new tab.
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'custom_link',
'title' => __('My custom link'),
'href' => __('http://www.google.com'),
'meta' => array(
'target' => '_blank',),
) );
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
Cheers!!!