How to create Repeater field in Redux Framework from wordpress? - php

Repeater field plugin is purchased in Redux framework. But I am creating it as a custom filed .
I have created 3 fields(title, phone, Textarea) with add more and delete button. In this, I want to add upload button along with that three fields . But I failed to add upload button . I tried a lot but it's not working .
Can you please tell me what is the way to add upload image button in custom field extension.

$fields = array(
'id'=>'multi-text',
'type' => 'multi_text',
'title' => __('Multi Text Option - Color Validated', 'textdomain'),
'validate' => 'color',
'subtitle' => __('If you enter an invalid color it will be removed. Try using the text "blue" as a color. ;)', 'texdoma'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo')
),
);
Example Usage
This example in based on the example usage provided above. Be sure to change $redux_demo to the value you specified in your opt_name argument.
global $redux_demo;
echo 'First Text Entry: ' . $redux_demo['multi-text'][0];
// The array number of additional entries will increase by one.

Related

Prepopulating gravityforms fields based on logged in users latest form entry

Can anyone help/have some ideas on how to prepopulate gravityforms fields based on users latest entry of the same form.
I've users, who will "register" to an event every year and fill the same form, so it would be nice to have the same fields already filled and if the client wants, they can refill some of the changed fields themselves.
So far I've found some info from gravityforms docs myself, but this code seems only to be prepopulating only one field? Still haven't gotten it to work.
The code ->
add_filter( 'gform_field_value_previous_value', 'populate_previous_value', 10, 2 );
function populate_previous_value( $value, $field ) {
$entries = GFAPI::get_entries(
$field->formId,
array(
'field_filters' => array(
array(
'key' => 'created_by',
'value' => get_current_user_id(),
),
),
),
array(),
array( 'page_size' => 1 )
);
return rgars( $entries, '0/' . $field->id );
}
I assume, the value between the rgars apostrophes aka the field id needs to be filled?
If anyone else is wondering/struggling to solve this issue - I've come to the realization that the best and easiest way to pre-populate fields values based on logged in user is through gravity forms merge tags.
Best way to use merge tags based on logged in user is next:
{user:[meta_tag}
You can use all the meta fields available, also the billing_address and billing_postcode and so on, as long as you include 'user:' before.
So the fields get populated based on logged in users meta fields. The merge tags need to be placed to form field->advanced->under default value.
For example if you need logged in users first name and last name to be populated you would add {user:first_name} to the first name default value field and {user:last_name} to the last name value field.

Add Advanced Custom Field to existing form on Dokan- Add product & edit product page (WordPress/WooCommerce)

I’m using a multi-vendor (Dokan) plugin, and been customizing it. One thing I want to achieve and been struggling is that I want my advanced custom field(also a plugin) for single product to actually appear on the front-end, in one of the Dokan’s seller dashboard form (Edit product section).
I want my seller to be able to select a brand (my acf field) on the fron-end page.
Normally when we add a new acf field group, and assign to the archive, the field will appear on the backend.
I found this to be pretty hard to achieve, especially adding the custom field onto an existing front-end form.
I have trying to customize it and I finally get the field to appear on the form I want to, but then another problem came up, which is the save button from the original form isn’t clickable anymore.
Please see screenshot: https://gyazo.com/dfb20ed90e773723658979c515581730
and here is the code I attempted to add into my Dokan’s single-product-new.php:
<?php acf_form_head(); ?>
<div class=”dokan-form-group”>
<?php
$product_brand = -1;
$term = array();
$term = wp_get_post_terms( $post_id, ‘brand’, array( ‘fields’ => ‘ids’) );
if ( $term ) {
$product_brand = reset( $term );
}
include_once DOKAN_LIB_DIR.’/class.category-walker.php’;
include_once DOKAN_LIB_DIR. ‘acf.php’;
$brand_args = array(
‘hierarchical’ => 1,
‘hide_empty’ => 0,
‘fields’ => array(‘brand’),
‘name’ => ‘brand’,
‘id’ => ‘brand’,
‘taxonomy’ => ‘brand’,
‘title_li’ => ”,
‘class’ => ‘product_brand dokan-form-control dokan-select2’,
‘exclude’ => ”,
‘selected’ => $product_brand,
‘walker’ => new DokanCategoryWalker( $post_id )
);
acf_form($brand_args);
?>
<div class=”dokan-product-cat-alert dokan-hide”>
<?php esc_html_e(‘Please choose a brand!’, ‘dokan-lite’ ); ?>
</div>
</div>
I know this is wrong, but somehow these code helped me to pull the advanced custom field onto the form I want, and it’s actually saving the field data to the product when you click update.
I was thinking maybe should of work around this under child-theme's function.php...
Any help will be really appreciated!
Luke
You can use a free plugin named ACF Frontend Form for Elementor to add / edit products from front end for your sellers / vendors.
https://wordpress.org/plugins/acf-frontend-form-element/
For this you also need to use elementor plugin and create a product page through elementor

How can I create a Custom Text Box on a WooCommerce Product Page?

I am working on a WordPress website, with WooCommerce functionality.
I have created 2 Custom Fields, for the Product Data box within the backend of the Product Page, using the following Code:
<?php
function theme_name_woocommerce_custom_fields() {
// Price Per Character
woocommerce_wp_text_input(
array(
'id' => '_character_price',
'label' => 'Price Per Character',
'description' => 'This is the amount a customer pays per letter entered.',
'desc_tip' => 'true',
'placeholder' => 'Enter Amount per Letter (Exclude the £)'
)
);
// Custom Text Box
woocommerce_wp_checkbox(
array(
'id' => '_custom_text_box',
'label' => 'Show Custom Text Box',
'description' => 'Select this box, if you would like a Custom Text Box to appear on the Product's page.',
'desc_tip' => 'true',
)
);
}
add_action( 'woocommerce_product_options_general_product_data', 'theme_name_woocommerce_custom_fields' );
function save_theme_name_woocommerce_custom_field( $post_id ) {
if ( ! empty( $_POST['_custom_text_field'] ) ) {
update_post_meta( $post_id, '_custom_text_field', esc_attr( $_POST['_custom_text_field'] ) );
}
}
add_action( 'woocommerce_process_product_meta', 'save_theme_name_woocommerce_custom_fields' );
?>
In reference to the woocommerce_wp_checkbox, I would like to create a function whereby when this checkbox is selected, it creates a Custom Text Box on the associated Product's page. This Custom Text Box can then be used by a potential customer to enter a piece of text, which they would like to have printed to the page's Product.
Is anyone aware of what additional piece of coding I would need to enter, in order to achieve said goal?
You can override simple/variable product's template file and add custom field there. Keep logic of show/hide textbox when checkbox is checked there only.
When add to cart is done, you will get all posted data in POST. Grab it from there and put into woocommerce' object.
=======================================================
Edited:
You can follow this steps:
Copy woocommerce/templates/single-product/add-to-cart/variable.php this template to your child theme and customize it. You will see a form tag there. In that you can put your custom created checkbox(which you added from admin). Also, add a custom textbox(in which user will enter text) - and hide it.
Add custom js from functions.php. - In this js you can write logic that if checkbox is checked then you will show the textbox, else not.
Now, when user does add to cart, add this custom textbox data to woocommerce object. How to enter custom data to woocommerce object - you can have step by step details here: https://wisdmlabs.com/blog/add-custom-data-woocommerce-order/

Updating logged in user's page when on other pages

I have a site that a user can sign up and build up their own profile page. This is done by creating a post when the user signs up, all the form data that is filled in is then saved to that post into the various custom fields. So essentially, every user has 1 post with all their profile data in.
Each user can see other people's profiles
I'm using the plugin http://www.advancedcustomfields.com and specifically using it's front end form capability.
When on the user's own profile, using the front end form capability, I can show a relationship field (http://www.advancedcustomfields.com/resources/field-types/relationship/), that then allows people to select other user's profile to essentially become a friend. This works great.
The problem I have is when a user goes to another person's profile, there is a "become a friend" button, when clicked, I want it to add that user's page to the current logged in users relationship field. Firstly, can that be done? If so, how?
Here's how I'm currently updating the relationship field when the logged in users on their own page (so they can add people).
<?php
$activity_information = array(
'post_id' => $post->ID, // post id to get field groups from and save data to
'field_groups' => array(58), // this will find the field groups for this post (post ID's of the acf post objects)
'form_attributes' => array( // attributes will be added to the form element
'class' => ''
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_field_open' => '<div>', // field wrapper open
'html_field_close' => '</div>', // field wrapper close
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => '', // default updated message. Can be false to show no message
);
?>
<?php acf_form( $activity_information ); ?>

Add key values in a array from outside of array

This is a php question, that happens to involve Wordpress.
My Wordpress parent theme adds a custom metabox. I need to add additional options to the metabox but I need to add the key values options from within my child theme...not in the parent theme where the array is created.
Adding the additional options (key values) in the parent theme is simple, but core theme files have to be changed and therefore will break when the partent theme is updated by the theme developer.
So I have made a child theme that handles all my custom adds...but I have no clue how to inject key vales into an array that is crated in the parent theme.
Here is an excerpt from the the array that builds the options for the metabox (parent theme):
$page_meta_boxes = array(
"Page Item" => array(
'item'=>'page-option-item-type' ,
'size'=>'page-option-item-size',
'xml'=>'page-option-item-xml',
'type'=>'page-option-item',
'name'=>array(
'home-page-featured'=>array(
'main-title'=>array(
'title'=> 'MAIN TITLE',
'name'=> 'page-option-item-featured-text-title',
'type'=> 'inputtext'),
'main-caption'=>array(
'title'=> 'MAIN CAPTION',
'name'=> 'page-option-item-stunning-text-caption',
'type'=> 'textarea'),
),
)
),
)
I want to add additional options to the metabox such as:
'get-started-button-title'=>array(
'title'=> 'GETTING STARTED BUTTON TITLE',
'name'=> 'page-option-item-featured-text-button-title',
'type'=> 'inputtext',
'description'=> 'The stunning text button will appear if this field is not a blank.'),
'get-started-button-link'=>array(
'title'=> 'GETTING STARTED BUTTON LINK',
'name'=> 'page-option-item-featured-text-button-link',
'type'=> 'inputtext',
'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'),
Is this even possible?
UPDATE:
What I have tried so far
I am including a file called options.php from within my child theme but its not adding the additional getting-started-button option.
$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(
'title'=> 'GETTING STARTED BUTTON LINK',
'name'=> 'page-option-item-featured-text-button-link',
'type'=> 'inputtext',
'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'
);
You could add additionnal options like this :
$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(....);
Be aware that even if you don't change the core theme. You rely on the way it is structured. So your code might still break in case of an update by the theme developer.

Categories