I have little issue when I customize my Dokan address form.php because I want to delete some filed and shift between them to.. but when I finished the verification page on vonder dashboard was stuck and not responding and because it's related to setting page on the vonder dashboard so it's stuck too. So I have advance knowledge of coding and want you guys to check out if there is any mistake I did to the codes and edit it for me.
Note: I was also translate the fields from English language to Arabic.
................
<?php
/**
* Dokan Settings Address form Template
*
* #since 2.4
*
* #package dokan
*/
$address = isset( $profile_info['address'] ) ? $profile_info['address'] : '';
$address_street1 = isset( $profile_info['address']['street_1'] ) ? $profile_info['address']['street_1'] : '';
$address_street2 = isset( $profile_info['address']['street_2'] ) ? $profile_info['address']['street_2'] : '';
$address_city = isset( $profile_info['address']['city'] ) ? $profile_info['address']['city'] : '';
$address_zip = isset( $profile_info['address']['zip'] ) ? $profile_info['address']['zip'] : '';
$address_country = isset( $profile_info['address']['country'] ) ? $profile_info['address']['country'] : '';
$address_state = isset( $profile_info['address']['state'] ) ? $profile_info['address']['state'] : '';
?>
<input type="hidden" id="dokan_selected_country" value="<?php echo esc_attr( $address_country )?>" />
<input type="hidden" id="dokan_selected_state" value="<?php echo esc_attr( $address_state ); ?>" />
<div class="dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address"><?php esc_html_e( 'العنوان', 'dokan-lite' ); ?></label>
<div class="dokan-w5 dokan-text-left dokan-address-fields">
<?php }
if ( $seller_address_fields['country'] ) {
$country_obj = new WC_Countries();
$countries = $country_obj->countries;
$states = $country_obj->states;
?>
<div class="dokan-form-group">
<label class="control-label" for="dokan_address[country]"><?php esc_html_e( 'الدولة ', 'dokan-lite' ); ?>
<?php
$required_attr = '';
if ( $seller_address_fields['country']['required'] ) {
$required_attr = 'required'; ?>
<span class="required"> *</span>
<?php } ?>
</label>
<select <?php echo esc_attr( $required_attr ); ?> <?php echo esc_attr( $disabled ) ?> name="dokan_address[country]" class="country_to_state dokan-form-control" id="dokan_address_country">
<?php dokan_country_dropdown( $countries, $address_country, false ); ?>
</select>
</div>
<?php }
if ( $seller_address_fields['state'] ) {
$address_state_class = '';
$is_input = false;
$no_states = false;
if ( isset( $states[$address_country] ) ) {
if ( empty( $states[$address_country] ) ) {
$address_state_class = 'dokan-hide';
$no_states = true;
}
} else {
$is_input = true;
}
?>
<div id="dokan-states-box" class="dokan-form-group">
<label class="control-label" for="dokan_address[state]"><?php esc_html_e( 'المحافظة ', 'dokan-lite' ); ?>
<?php
$required_attr = '';
if ( $seller_address_fields['state']['required'] ) {
$required_attr = 'required'; ?>
<span class="required"> *</span>
<?php } ?>
</label>
<?php if ( $is_input ) {
$required_attr = '';
if ( $seller_address_fields['state']['required'] ) {
$required_attr = 'required';
}
?>
<input <?php echo esc_attr( $required_attr ); ?> <?php echo esc_attr( $disabled ) ?> name="dokan_address[state]" class="dokan-form-control <?php echo esc_attr( $address_state_class ) ?>" id="dokan_address_state" value="<?php echo esc_attr( $address_state ) ?>"/>
<?php } else {
$required_attr = '';
if ( $seller_address_fields['state']['required'] ) {
$required_attr = 'required';
}
?>
<select <?php echo esc_attr( $required_attr ); ?> <?php echo esc_attr( $disabled ) ?> name="dokan_address[state]" class="dokan-form-control" id="dokan_address_state">
<?php dokan_state_dropdown( $states[$address_country], $address_state ) ?>
</select>
<?php } ?>
</div>
<?php if ( $seller_address_fields['street_1'] ) { ?>
<div class="dokan-form-group">
<label class="control-label" for="dokan_address[street_1]"><?php esc_html_e( 'الولاية ', 'dokan-lite' ); ?>
<?php
$required_attr = '';
if ( $seller_address_fields['street_1']['required'] ) {
$required_attr = 'required'; ?>
<span class="required"> *</span>
<?php } ?>
</label>
<input <?php echo esc_attr( $required_attr ); ?> <?php echo esc_attr( $disabled ) ?> id="dokan_address[street_1]" value="<?php echo esc_attr( $address_street1 ); ?>" name="dokan_address[street_1]" placeholder="<?php esc_attr_e( 'القرية/المنطقة' , 'dokan-lite' ) ?>" class="dokan-form-control input-md" type="text">
</div>
<?php }
if ( $seller_address_fields['street_2'] ) { ?>
<div class="dokan-form-group">
<label class="control-label" for="dokan_address[street_2]"><?php esc_html_e( 'رقم المنزل/رقم الشارع', 'dokan-lite' ); ?>
<?php
$required_attr = '';
if ( $seller_address_fields['street_2']['required'] ) {
$required_attr = 'required'; ?>
<span class="required"> *</span>
<?php } ?>
</label>
<input <?php echo esc_attr( $required_attr ); ?> <?php echo esc_attr( $disabled ) ?> id="dokan_address[street_2]" value="<?php echo esc_attr( $address_street2 ); ?>" name="dokan_address[street_2]" placeholder="<?php esc_attr_e( 'معلومات اخرى' , 'dokan-lite' ) ?>" class="dokan-form-control input-md" type="text">
</div>
<?php } ?>
<?php
/**
* Add vendor address verification templates.
*
* #since 3.4.2
*
* #param array $address Vendor address info.
* #param array $seller_address_fields Vendor required addresses.
*/
do_action( 'dokan_vendor_address_verification_template', $address, $seller_address_fields );
?>
</div>
</div>
Related
I want to combine two forms from two different plugins namely : Wp job manager (Plugin A) and Afj Company Listings (plugin B). plugin A has a form called job-submit.php (located in: public_html/wp-content/plugins/wp-job-manager/templates) which would like to combine with another form from Plugin B called company_listings-submit.php (located in: public_html/wp-content/plugins/afj-company-listings/templates).
What I have done is to add get method in the job-submit.php but didnt work:
get_afj_company_listings_template( 'company_listings-submit.php' )
job-submit.php
/**
Content for job submission ([submit_job_form]) shortcode.
This template can be overridden by copying it to yourtheme/job_manager/job-submit.php.
#see https://wpjobmanager.com/document/template-overrides/
#author Automattic
#package wp-job-manager
#category Template
#version 1.34.3
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
global $job_manager;
?>
" method="post" id="submit-job-form" class="job-manager-form" enctype="multipart/form-data">
<?php
if ( isset( $resume_edit ) && $resume_edit ) {
printf( '<p><strong>' . esc_html__( "You are editing an existing job. %s", 'wp-job-manager' ) . '</strong></p>', '' . esc_html__( 'Create A New Job', 'wp-job-manager' ) . '' );
}
?>
<?php do_action( 'submit_job_form_start' ); ?>
<?php if ( apply_filters( 'submit_job_form_show_signin', true ) ) : ?>
<?php get_job_manager_template( 'account-signin.php' ); ?>
<?php endif; ?>
<?php if ( job_manager_user_can_post_job() || job_manager_user_can_edit_job( $job_id ) ) : ?>
<!-- Job Information Fields -->
<?php do_action( 'submit_job_form_job_fields_start' ); ?>
<!-- MY OWN CODE HERE-----afj-company-listings/templates/company_listings-submit.php wp-content/plugins/wp-job-manager/templates-->
<?php get_job_manager_template( 'company_listings-submit.php' ); ?>
<?php foreach ( $job_fields as $key => $field ) : ?>
<fieldset class="fieldset-<?php echo esc_attr( $key ); ?> fieldset-type-<?php echo esc_attr( $field['type'] ); ?>">
<label for="<?php echo esc_attr( $key ); ?>"><?php echo wp_kses_post(
$field['label'] ) . wp_kses_post( apply_filters( 'submit_job_form_required_label',
$field['required'] ? '' : ' ' . __( '(optional)', 'wp-job-manager' ) . '', $field )
); ?>
">
<?php get_job_manager_template( 'form-fields/' . $field['type'] . '-
field.php', [ 'key' => $key, 'field' => $field ] ); ?>
</div>
</fieldset>
<?php endforeach; ?>
<?php do_action( 'submit_job_form_job_fields_end' ); ?>
<!-- Company Information Fields -->
<?php if ( $company_fields ) : ?>
<h2><?php esc_html_e( 'Company Details', 'wp-job-manager' ); ?></h2>
<?php do_action( 'submit_job_form_company_fields_start' ); ?>
<?php foreach ( $company_fields as $key => $field ) : ?>
<fieldset class="fieldset-<?php echo esc_attr( $key ); ?> fieldset-type-<?php echo esc_attr( $field['type'] ); ?>">
<label for="<?php echo esc_attr( $key ); ?>"><?php echo wp_kses_post(
$field['label'] ) . wp_kses_post( apply_filters( 'submit_job_form_required_label',
$field['required'] ? '' : ' ' . __( '(optional)', 'wp-job-manager' ) . '', $field ) ); ?>
">
<?php get_job_manager_template( 'form-fields/' . $field['type'] . '-field.php', [ 'key' => $key, 'field' => $field ] ); ?>
</div>
</fieldset>
<?php endforeach; ?>
<?php do_action( 'submit_job_form_company_fields_end' ); ?>
<?php endif; ?>
<?php do_action( 'submit_job_form_end' ); ?>
<p>
<input type="hidden" name="job_manager_form" value="<?php echo esc_attr( $form ); ?>" />
<input type="hidden" name="job_id" value="<?php echo esc_attr( $job_id ); ?>" />
<input type="hidden" name="step" value="<?php echo esc_attr( $step ); ?>" />
<input type="submit" name="submit_job" class="button" value="<?php echo esc_attr(
$submit_button_text ); ?>" />
<?php
if ( isset( $can_continue_later ) && $can_continue_later ) {
echo '<input type="submit" name="save_draft" class="button secondary save_draft"
value="' . esc_attr__( 'Save Draft', 'wp-job-manager' ) . '" formnovalidate />';
}
?>
<span class="spinner" style="background-image: url(<?php echo esc_url( includes_url(
'images/spinner.gif' ) ); ?>);">
</p>
<?php else : ?>
<?php do_action( 'submit_job_form_disabled' ); ?>
<?php endif; ?>
company_listings-submit.php
" method="post" id="submit-company-form" class="job-manager-form" enctype="multipart/form-data">
<?php do_action( 'submit_company_form_start' ); ?>
<?php if ( apply_filters( 'submit_company_form_show_signin', true ) ) : ?>
<?php get_job_manager_template( 'account-signin.php', array( 'class' => $class ), 'afj-company-listings', COMPANY_LISTINGS_PLUGIN_DIR . '/templates/' ); ?>
<?php endif; ?>
<?php if ( company_listings_user_can_post_company() ) : ?>
<!-- Company Fields -->
<?php do_action( 'submit_company_form_company_fields_start' ); ?>
<?php foreach ( $company_fields as $key => $field ) : ?>
<fieldset class="fieldset-<?php esc_attr_e( $key ); ?>">
<label for="<?php esc_attr_e( $key ); ?>"><?php echo $field['label'] . apply_filters( 'submit_company_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'afj-company-listings' ) . '</small>', $field ); ?></label>
<div class="field">
<?php $class->get_field_template( $key, $field ); ?>
</div>
</fieldset>
<?php endforeach; ?>
<?php do_action( 'submit_company_form_company_fields_end' ); ?>
<p>
<?php wp_nonce_field( 'submit_form_posted' ); ?>
<input type="hidden" name="company_listings_form" value="<?php echo $form; ?>" />
<input type="hidden" name="company_id" value="<?php echo esc_attr( $company_id ); ?>" />
<input type="hidden" name="job_id" value="<?php echo esc_attr( $job_id ); ?>" />
<input type="hidden" name="step" value="<?php echo esc_attr( $step ); ?>" />
<input type="submit" name="submit_company" class="button" value="<?php esc_attr_e( $submit_button_text ); ?>" />
</p>
<?php else : ?>
<?php do_action( 'submit_company_form_disabled' ); ?>
<?php endif; ?>
<?php do_action( 'submit_company_form_end' ); ?>
I found this code which has allowed me to add custom fields to the advanced options in the Wordpress menu editor:
/*
* Saves new field to postmeta for navigation
*/
add_action('wp_update_nav_menu_item', 'megamenu_nav_update',10, 3);
function megamenu_nav_update($menu_id, $menu_item_db_id, $args ) {
if ( is_array($_REQUEST['menu-item-megamenu']) ) {
$megamenu_value = $_REQUEST['menu-item-megamenu'][$menu_item_db_id];
update_post_meta( $menu_item_db_id, '_menu_item_megamenu', $megamenu_value );
}
if ( is_array($_REQUEST['menu-item-megamenu_col']) ) {
$megamenu_col_value = $_REQUEST['menu-item-megamenu_col'][$menu_item_db_id];
update_post_meta( $menu_item_db_id, '_menu_item_megamenu_col', $megamenu_col_value );
}
if ( is_array($_REQUEST['menu-item-megamenu_alignment']) ) {
$megamenu_alignment_value = $_REQUEST['menu-item-megamenu_alignment'][$menu_item_db_id];
update_post_meta( $menu_item_db_id, '_menu_item_megamenu_alignment', $megamenu_alignment_value );
}
}
/*
* Adds value of new field to $item object that will be passed to Walker_Nav_Menu_Edit_Custom
*/
add_filter( 'wp_setup_nav_menu_item','megamenu_nav_item' );
function megamenu_nav_item($menu_item) {
$menu_item->megamenu = get_post_meta( $menu_item->ID, '_menu_item_megamenu', true );
$menu_item->megamenu_col = get_post_meta( $menu_item->ID, '_menu_item_megamenu_col', true );
$menu_item->megamenu_alignment = get_post_meta( $menu_item->ID, '_menu_item_megamenu_alignment', true );
return $menu_item;
}
add_filter( 'wp_edit_nav_menu_walker', 'custom_nav_edit_walker',10,2 );
function custom_nav_edit_walker($walker,$menu_id) {
return 'Walker_Nav_Menu_Edit_Custom';
}
/**
* Copied from Walker_Nav_Menu_Edit class in core
*
* Create HTML list of nav menu input items.
*
* #package WordPress
* #since 3.0.0
* #uses Walker_Nav_Menu
*/
class Walker_Nav_Menu_Edit_Custom extends Walker_Nav_Menu {
/**
* #see Walker_Nav_Menu::start_lvl()
* #since 3.0.0
*
* #param string $output Passed by reference.
*/
function start_lvl(&$output, $depth = 0, $args = array()) {
}
/**
* #see Walker_Nav_Menu::end_lvl()
* #since 3.0.0
*
* #param string $output Passed by reference.
*/
function end_lvl(&$output, $depth = 0, $args = array()) {
}
/**
* #see Walker::start_el()
* #since 3.0.0
*
* #param string $output Passed by reference. Used to append additional content.
* #param object $item Menu item data object.
* #param int $depth Depth of menu item. Used for padding.
* #param object $args
*/
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
global $_wp_nav_menu_max_depth;
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
ob_start();
$item_id = esc_attr( $item->ID );
$removed_args = array(
'action',
'customlink-tab',
'edit-menu-item',
'menu-item',
'page-tab',
'_wpnonce',
);
$original_title = '';
if ( 'taxonomy' == $item->type ) {
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
if ( is_wp_error( $original_title ) )
$original_title = false;
} elseif ( 'post_type' == $item->type ) {
$original_object = get_post( $item->object_id );
$original_title = $original_object->post_title;
}
$classes = array(
'menu-item menu-item-depth-' . $depth,
'menu-item-' . esc_attr( $item->object ),
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
);
$title = $item->title;
if ( ! empty( $item->_invalid ) ) {
$classes[] = 'menu-item-invalid';
/* translators: %s: title of menu item which is invalid */
$title = sprintf( __( '%s (Invalid)','rdesign' ), $item->title );
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
$classes[] = 'pending';
/* translators: %s: title of menu item in draft status */
$title = sprintf( __('%s (Pending)','rdesign'), $item->title );
}
$title = empty( $item->label ) ? $title : $item->label;
?>
<li id="menu-item-<?php echo esc_attr($item_id); ?>" class="<?php echo implode(' ', $classes ); ?>">
<dl class="menu-item-bar">
<dt class="menu-item-handle">
<span class="item-title"><?php echo esc_html( $title ); ?></span>
<span class="item-controls">
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
<span class="item-order hide-if-js">
<a href="<?php
echo wp_nonce_url( esc_url( add_query_arg(
array(
'action' => 'move-up-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' )))
),
'move-menu_item'
);
?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up','rdesign'); ?>">↑</abbr></a>
|
<a href="<?php
echo wp_nonce_url(
esc_url( add_query_arg(
array(
'action' => 'move-down-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) )
),
'move-menu_item'
);
?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down','rdesign'); ?>">↓</abbr></a>
</span>
<a class="item-edit" id="edit-<?php echo esc_attr($item_id); ?>" title="<?php esc_attr_e('Edit Menu Item','rdesign'); ?>" href="<?php
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : esc_url( add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) ) );
?>"><?php _e( 'Edit Menu Item','rdesign' ); ?></a>
</span>
</dt>
</dl>
<div class="menu-item-settings" id="menu-item-settings-<?php echo esc_attr($item_id); ?>">
<?php if( 'custom' == $item->type ) : ?>
<p class="field-url description description-wide">
<label for="edit-menu-item-url-<?php echo esc_attr($item_id); ?>">
<?php _e( 'URL','rdesign' ); ?><br />
<input type="text" id="edit-menu-item-url-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
</label>
</p>
<?php endif; ?>
<p class="description description-thin">
<label for="edit-menu-item-title-<?php echo esc_attr($item_id); ?>">
<?php _e( 'Navigation Label','rdesign' ); ?><br />
<input type="text" id="edit-menu-item-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
</label>
</p>
<p class="description description-thin">
<label for="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>">
<?php _e( 'Title Attribute','rdesign' ); ?><br />
<input type="text" id="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
</label>
</p>
<p class="field-link-target description">
<label for="edit-menu-item-target-<?php echo esc_attr($item_id); ?>">
<input type="checkbox" id="edit-menu-item-target-<?php echo esc_attr($item_id); ?>" value="_blank" name="menu-item-target[<?php echo esc_attr($item_id); ?>]"<?php checked( $item->target, '_blank' ); ?> />
<?php _e( 'Open link in a new window/tab','rdesign' ); ?>
</label>
</p>
<p class="field-css-classes description description-thin">
<label for="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>">
<?php _e( 'CSS Classes (optional)','rdesign' ); ?><br />
<input type="text" id="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
</label>
</p>
<p class="field-xfn description description-thin">
<label for="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>">
<?php _e( 'Link Relationship (XFN)','rdesign' ); ?><br />
<input type="text" id="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
</label>
</p>
<?php
/* New fields insertion starts here */
?>
<p class="field-megamenu-status description description-wide">
<label for="edit-menu-item-megamenu-<?php echo esc_attr($item_id); ?>">
<input type="checkbox" id="edit-menu-item-megamenu-<?php echo esc_attr($item_id); ?>" value="megamenu" name="menu-item-megamenu[<?php echo esc_attr($item_id); ?>]"<?php checked( $item->megamenu, 'megamenu' ); ?> />
<?php _e( 'Enable megamenu','rdesign' ); ?>
</label>
</p>
<p class="field-megamenu-columns description description-wide">
<label for="edit-menu-item-megamenu_col-<?php echo esc_attr($item_id); ?>">
<?php _e( 'Megamenu columns (from 2 to 6)','rdesign' ); ?><br />
<?php $saved_megamenu_col = esc_attr( $item->megamenu_col ); ?>
<select id="edit-menu-item-megamenu_col-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-custom" name="menu-item-megamenu_col[<?php echo esc_attr($item_id); ?>]">
<option value="2" <?php if($saved_megamenu_col == "2"){echo("selected");} ?>>2</option>
<option value="3" <?php if($saved_megamenu_col == "3"){echo("selected");} ?>>3</option>
<option value="4" <?php if($saved_megamenu_col == "4"){echo("selected");} ?>>4</option>
<option value="5" <?php if($saved_megamenu_col == "5"){echo("selected");} ?>>5</option>
<option value="6" <?php if($saved_megamenu_col == "6"){echo("selected");} ?>>6</option>
</select>
</label>
</p>
<p class="field-megamenu-alignment description description-wide">
<label for="edit-menu-item-megamenu_alignment-<?php echo esc_attr($item_id); ?>">
<?php _e( 'Megamenu alignment','rdesign' ); ?><br />
<?php $saved_megamenu_alignment = esc_attr( $item->megamenu_alignment ); ?>
<select id="edit-menu-item-megamenu_alignment-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-custom" name="menu-item-megamenu_alignment[<?php echo esc_attr($item_id); ?>]">
<option value="left" <?php if($saved_megamenu_alignment == "left"){echo("selected");} ?>>Left</option>
<option value="center" <?php if($saved_megamenu_alignment == "center"){echo("selected");} ?>>Center</option>
<option value="right" <?php if($saved_megamenu_alignment == "right"){echo("selected");} ?>>Right</option>
<option value="space-around" <?php if($saved_megamenu_alignment == "space-around"){echo("selected");} ?>>Space Around</option>
<option value="space-evenly" <?php if($saved_megamenu_alignment == "space-evenly"){echo("selected");} ?>>Space Evenly</option>
<option value="space-between" <?php if($saved_megamenu_alignment == "space-between"){echo("selected");} ?>>Space Between</option>
</select>
</label>
</p>
<?php
/* New fields insertion ends here */
?>
<div class="menu-item-actions description-wide submitbox">
<?php if( 'custom' != $item->type && $original_title !== false ) : ?>
<p class="link-to-original">
<?php printf( __('Original: %s','rdesign'), '' . esc_html( $original_title ) . '' ); ?>
</p>
<?php endif; ?>
<a class="item-delete submitdelete deletion" id="delete-<?php echo esc_attr($item_id); ?>" href="<?php
echo wp_nonce_url(
esc_url( add_query_arg(
array(
'action' => 'delete-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) )
),
'delete-menu_item_' . $item_id
); ?>"><?php _e('Remove','rdesign'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo esc_attr($item_id); ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
?>#menu-item-settings-<?php echo esc_attr($item_id); ?>"><?php _e('Cancel','rdesign'); ?></a>
</div>
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr($item_id); ?>" />
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
</div><!-- .menu-item-settings-->
<ul class="menu-item-transport"></ul>
<?php
$output .= ob_get_clean();
}
}
This code has allowed me to add a checkbox field to enable Megamenu, a dropdown field to select 2 - 6 columns for the Megamenu and a dropdown field to select the megamenu item alignment.
What I need to know now, however, is having saved these options, how can I now add classes to the navigation menu items based on the saved values? i.e., if Megamenu is enabled, I need the class "mega-menu" to be added to the menu item <li>.
Ok, I have managed to get this working using the following code:
add_filter('nav_menu_css_class' , 'megamenu_nav_classes' , 10 , 2);
function megamenu_nav_classes($classes, $item){
$item_id = esc_attr( $item->ID );
$mega_menu = $item->$megamenu['_menu_item_megamenu'][0];
$mega_menu_col = $item->$megamenu['_menu_item_megamenu_col'][0];
$mega_menu_alignment = $item->$megamenu['_menu_item_megamenu_alignment'][0];
if($mega_menu == 'megamenu'){
$classes[] = 'mega-menu';
$classes[] = 'col-'.$mega_menu_col;
$classes[] = $mega_menu_alignment;
}
return $classes;
}
This does work, but can anyone tell me if this is the best way of going about this? Or is there a better, 'cleaner' method?
I'd like to switch the order of the 'Billing City' and the 'Billing ZIP' field in the code below through a snippet in my functions.php file. I've been on it for hours, but I can't get it right. This is the code in the easy-digital-downloads/includes/checkout/template.php file, thank you so much for helping out:
<?php
do_action( 'edd_after_cc_fields' );
echo ob_get_clean();
}
add_action( 'edd_cc_form', 'edd_get_cc_form' );
/**
* Outputs the default credit card address fields
*
* #since 1.0
* #return void
*/
function edd_default_cc_address_fields() {
$logged_in = is_user_logged_in();
$customer = EDD()->session->get( 'customer' );
$customer = wp_parse_args( $customer, array( 'address' => array(
'line1' => '',
'line2' => '',
'city' => '',
'zip' => '',
'state' => '',
'country' => ''
) ) );
$customer['address'] = array_map( 'sanitize_text_field', $customer['address'] );
if( $logged_in ) {
$user_address = get_user_meta( get_current_user_id(), '_edd_user_address', true );
foreach( $customer['address'] as $key => $field ) {
if ( empty( $field ) && ! empty( $user_address[ $key ] ) ) {
$customer['address'][ $key ] = $user_address[ $key ];
} else {
$customer['address'][ $key ] = '';
}
}
}
/**
* Billing Address Details.
*
* Allows filtering the customer address details that will be pre-populated on the checkout form.
*
* #since 2.8
*
* #param array $address The customer address.
* #param array $customer The customer data from the session
*/
$customer['address'] = apply_filters( 'edd_checkout_billing_details_address', $customer['address'], $customer );
ob_start(); ?>
<fieldset id="edd_cc_address" class="cc-address">
<legend><?php _e( 'Billing Details', 'easy-digital-downloads' ); ?></legend>
<?php do_action( 'edd_cc_billing_top' ); ?>
<p id="edd-card-address-wrap">
<label for="card_address" class="edd-label">
<?php _e( 'Billing Address', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'card_address' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The primary billing address for your credit card.', 'easy-digital-downloads' ); ?></span>
<input type="text" id="card_address" name="card_address" class="card-address edd-input<?php if( edd_field_is_required( 'card_address' ) ) { echo ' required'; } ?>" placeholder="<?php _e( 'Address line 1', 'easy-digital-downloads' ); ?>" value="<?php echo $customer['address']['line1']; ?>"<?php if( edd_field_is_required( 'card_address' ) ) { echo ' required '; } ?>/>
</p>
<p id="edd-card-address-2-wrap">
<label for="card_address_2" class="edd-label">
<?php _e( 'Billing Address Line 2 (optional)', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'card_address_2' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The suite, apt no, PO box, etc, associated with your billing address.', 'easy-digital-downloads' ); ?></span>
<input type="text" id="card_address_2" name="card_address_2" class="card-address-2 edd-input<?php if( edd_field_is_required( 'card_address_2' ) ) { echo ' required'; } ?>" placeholder="<?php _e( 'Address line 2', 'easy-digital-downloads' ); ?>" value="<?php echo $customer['address']['line2']; ?>"<?php if( edd_field_is_required( 'card_address_2' ) ) { echo ' required '; } ?>/>
</p>
<p id="edd-card-city-wrap">
<label for="card_city" class="edd-label">
<?php _e( 'Billing City', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'card_city' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The city for your billing address.', 'easy-digital-downloads' ); ?></span>
<input type="text" id="card_city" name="card_city" class="card-city edd-input<?php if( edd_field_is_required( 'card_city' ) ) { echo ' required'; } ?>" placeholder="<?php _e( 'City', 'easy-digital-downloads' ); ?>" value="<?php echo $customer['address']['city']; ?>"<?php if( edd_field_is_required( 'card_city' ) ) { echo ' required '; } ?>/>
</p>
<p id="edd-card-zip-wrap">
<label for="card_zip" class="edd-label">
<?php _e( 'Billing Zip / Postal Code', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'card_zip' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The zip or postal code for your billing address.', 'easy-digital-downloads' ); ?></span>
<input type="text" size="4" id="card_zip" name="card_zip" class="card-zip edd-input<?php if( edd_field_is_required( 'card_zip' ) ) { echo ' required'; } ?>" placeholder="<?php _e( 'Zip / Postal Code', 'easy-digital-downloads' ); ?>" value="<?php echo $customer['address']['zip']; ?>"<?php if( edd_field_is_required( 'card_zip' ) ) { echo ' required '; } ?>/>
</p>
<p id="edd-card-country-wrap">
<label for="billing_country" class="edd-label">
<?php _e( 'Billing Country', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'billing_country' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The country for your billing address.', 'easy-digital-downloads' ); ?></span>
<select name="billing_country" id="billing_country" data-nonce="<?php echo wp_create_nonce( 'edd-country-field-nonce' ); ?>" class="billing_country edd-select<?php if( edd_field_is_required( 'billing_country' ) ) { echo ' required'; } ?>"<?php if( edd_field_is_required( 'billing_country' ) ) { echo ' required '; } ?>>
<?php
$selected_country = edd_get_shop_country();
if( ! empty( $customer['address']['country'] ) && '*' !== $customer['address']['country'] ) {
$selected_country = $customer['address']['country'];
}
$countries = edd_get_country_list();
foreach( $countries as $country_code => $country ) {
echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
}
?>
</select>
</p>
<p id="edd-card-state-wrap">
<label for="card_state" class="edd-label">
<?php _e( 'Billing State / Province', 'easy-digital-downloads' ); ?>
<?php if( edd_field_is_required( 'card_state' ) ) { ?>
<span class="edd-required-indicator">*</span>
<?php } ?>
</label>
<span class="edd-description"><?php _e( 'The state or province for your billing address.', 'easy-digital-downloads' ); ?></span>
<?php
$selected_state = edd_get_shop_state();
$states = edd_get_shop_states( $selected_country );
if( ! empty( $customer['address']['state'] ) ) {
$selected_state = $customer['address']['state'];
}
if( ! empty( $states ) ) : ?>
<select name="card_state" id="card_state" class="card_state edd-select<?php if( edd_field_is_required( 'card_state' ) ) { echo ' required'; } ?>">
<?php
foreach( $states as $state_code => $state ) {
echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
}
?>
</select>
<?php else : ?>
<?php $customer_state = ! empty( $customer['address']['state'] ) ? $customer['address']['state'] : ''; ?>
<input type="text" size="6" name="card_state" id="card_state" class="card_state edd-input" value="<?php echo esc_attr( $customer_state ); ?>" placeholder="<?php _e( 'State / Province', 'easy-digital-downloads' ); ?>"/>
<?php endif; ?>
</p>
<?php do_action( 'edd_cc_billing_bottom' ); ?>
<?php wp_nonce_field( 'edd-checkout-address-fields', 'edd-checkout-address-fields-nonce', false, true ); ?>
</fieldset>
<?php
echo ob_get_clean();
}
add_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields' );
Ok, based on your comments i would say the EASIEST (not the cleanest) way to achieve that is to include a small piece of JS to move the DIV
$("#edd-card-zip-wrap").insertBefore("#edd-card-city-wrap");
That should be enought :)
Edit:
Paste this code into your theme's functions.php
add_action( 'wp_enqueue_scripts', 'enqueue_my_script' );
function enqueue_my_script() {
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/my-script.js', array( "jquery" ), false, true );
}
This will search for a file named "my-script.js" that lives in the root folder of your theme (same level as the functions.php file)
That file content can be something like this:
Edited with fixed wait:
$("document").ready(function() {
var waitThisTime = 1000; // Wait this ms. 1000ms = 1sec
setTimeout(function(){
$("#edd-card-zip-wrap").insertBefore("#edd-card-city-wrap");
},waitThisTime);
});
You can do that by using below code snippet.
add_filter( 'woocommerce_checkout_fields', 'ro_postcode_city_interchange' );
function ro_postcode_city_interchange( $checkout_fields ) {
$checkout_fields['billing']['billing_postcode']['priority'] = 70;
$checkout_fields['billing']['billing_city']['priority'] = 90;
return $checkout_fields;
}
This code snipper will interchange the order as all fields have their priority so here you have to give postcode priority of city and city priority of zipcode.
Tested and works well.
I tried modifying this plug-in for WordPress:
https://easydigitaldownloads.com/downloads/custom-prices/?utm_campaign=documentation&utm_source=helpscout&utm_medium=doc&utm_term=1975-custom-prices-overview
What I'm trying to achieve is moving the $ sign next to the custom price field or alternatively removing it completely.
/*
* Hook into add to cart post
*/
function edd_cp_purchase_link_top( $download_id ) {
global $edd_options;
$default_price = get_post_meta( $download_id, 'edd_cp_default_price', true );
$min_price = edd_format_amount ( get_post_meta( $download_id, 'edd_cp_min', true ) );
$custom_price = isset( $_GET ['cp_price'] ) ? edd_format_amount( $_GET ['cp_price'] ) : '';
$button_text = get_post_meta( $download_id, 'cp_button_text', true );
if ( empty( $custom_price ) && ! empty( $default_price ) ) {
$custom_price = edd_format_amount( $default_price );
}
if ( edd_cp_has_custom_pricing( $download_id ) && ! edd_single_price_option_mode( $download_id ) ) {
$wrapper_display = '';
$download = new EDD_Download( $download_id );
if ( edd_item_in_cart( $download_id, array() ) && ( ! $download->has_variable_prices() || ! $download->is_single_price_mode() ) ) {
$wrapper_display = 'style="display:none;"';
} ?>
<p class="edd-cp-container" <?php echo $wrapper_display; ?>>
<?php
echo __( 'Name your price', 'edd_cp' );
if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<?php echo edd_currency_filter( '' ); ?> <input type="text" name="edd_cp_price" class="edd_cp_price" value="<?php echo esc_attr( $custom_price ); ?>" size="30" data-min="<?php echo $min_price; ?>" style="width: 40px;" data-default-text="<?php echo esc_attr( $button_text ); ?>" />
<?php else : ?>
<input type="text" name="edd_cp_price" class="edd_cp_price" value="<?php echo esc_attr( $custom_price ); ?>" size="30" data-min="<?php echo $min_price; ?>" style="width: 80px;" data-default-text="<?php echo esc_attr( $button_text ); ?>" /><?php echo edd_currency_filter( '' );
endif;
$min_no_format = floatval( $min_price );
if( !empty( $min_no_format ) ) {
echo ' <small>(min '.edd_currency_filter( ( $min_price ) ).')</small>';
} ?>
</p>
<?php
}
}
add_filter( 'edd_purchase_link_top', 'edd_cp_purchase_link_top' );
/*
* Add additional list item if variable pricing is enabled
*/
function edd_cp_after_price_options_list( $key, $price, $download_id ) {
if( ! edd_cp_has_custom_pricing( $download_id ) ) {
return;
}
if ( ! edd_single_price_option_mode( $download_id ) ) {
return;
}
global $edd_options;
$default_price_option = edd_get_default_variable_price( $download_id );
$display = 'none';
if ( $key === $default_price_option ) {
$display = 'block';
} ?>
<div class="edd-cp-price-option-wrapper" style="display: <?php echo esc_attr( $display ); ?>;">
<?php
echo __( 'Name your price', 'edd_cp' );
if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<?php echo edd_currency_filter( '' ); ?> <input type="text" name="edd_cp_price[<?php echo esc_attr( $key ); ?>]" class="edd_cp_price" value="<?php echo esc_attr( $price['amount'] ); ?>" size="30" data-min="" />
<?php else : ?>
<input type="text" name="edd_cp_price[<?php echo esc_attr( $key ); ?>]" class="edd_cp_price" value="<?php echo esc_attr( $price['amount'] ); ?>" size="30" data-min="" data-default-text="<?php echo esc_attr( $button_text ); ?>" /><?php echo edd_currency_filter( '' );
endif; ?>
</div>
<?php }
add_action( 'edd_after_price_option', 'edd_cp_after_price_options_list', 10, 3 );
See the attached image. This is how it currently looks.
I really appreciate your help!
how to query woocommerce shipping method tax price ?
Porblem i don't tax + prive query!
Price query:
<?php if($method->cost > 0) : ?>+<span style="font-weight: normal"><?= $method->cost ?> Ft</span><?php endif; ?>
</label>
</div>
My code is:
<h2>Átvételi mód</h2>
<?php
$packages = WC()->shipping->get_packages();
$first = true;
foreach ($packages as $i => $package) {
$chosen_method = isset(WC()->session->chosen_shipping_methods[$i]) ? WC()->session->chosen_shipping_methods[$i] : '';
$product_names = array();
if (sizeof($packages) > 1) {
foreach ($package['contents'] as $item_id => $values) {
$product_names[$item_id] = $values['data']->get_name() . ' ×' . $values['quantity'];
}
$product_names = apply_filters('woocommerce_shipping_package_details_array', $product_names, $package);
}
/** #var WC_Shipping_Rate[] $available_methods */
$available_methods = $package['rates'];
$show_package_details = sizeof( $packages ) > 1;
$package_name = apply_filters( 'woocommerce_shipping_package_name', sprintf( _nx( 'Shipping', 'Shipping %d', ( $i + 1 ), 'shipping packages', 'woocommerce' ), ( $i + 1 ) ), $i, $package );
?>
<div class="shipping atvetelimod">
<td data-title="<?php echo esc_attr( $package_name ); ?>">
<?php if ( 1 < count( $available_methods ) ) : ?>
<div id="shipping_method row">
<?php
foreach ( $available_methods as $method ) : ?>
<div class="col-lg-6 balraszoveg">
<div class="jobbelvalaszto">
<label class="checkjel">
<input class="legyenelottefeher" type="radio" name="shipping_method[<?= $i ?>]" data-index="<?= $i ?>" id="shipping_method_<?= $i ?>_<?= sanitize_title( $method->id ) ?>" value="<?= esc_attr( $method->id ) ?>" class="shipping_method" <?= checked( $method->id, $chosen_method, false ) ?> />
</label>
</div>
<label class="jobboldaliszoveg" for="shipping_method_<?= $i ?>_<?= sanitize_title( $method->id ) ?>">
<strong><?= $method->get_label() ?></strong><br />
<?php if($method->cost > 0) : ?>+<span style="font-weight: normal"><?= $method->cost ?> Ft</span><?php endif; ?>
</label>
</div>
<?php endforeach; ?>
</div>
<?php elseif ( 1 === count( $available_methods ) ) : ?>
<?php
$method = current( $available_methods );
printf( '%3$s <input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d" value="%2$s" class="shipping_method" />', $index, esc_attr( $method->id ), wc_cart_totals_shipping_method_label( $method ) );
do_action( 'woocommerce_after_shipping_rate', $method, $index );
?>
<?php elseif ( WC()->customer->has_calculated_shipping() ) : ?>
<?php echo apply_filters( is_cart() ? 'woocommerce_cart_no_shipping_available_html' : 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) ); ?>
<?php elseif ( ! is_cart() ) : ?>
<?php echo wpautop( __( 'Enter your full address to see shipping costs.', 'woocommerce' ) ); ?>
<?php endif; ?>
<?php if ( $show_package_details ) : ?>
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
<?php endif; ?>
<?php if ( ! empty( $show_shipping_calculator ) ) : ?>
<?php woocommerce_shipping_calculator(); ?>
<?php endif; ?>
</td>
</div>
<?php }; ?>