Get payment gateway related data in Woocommerce - php

I have this code to set WooCommerce variables
// Defining User set variables
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' );
but how to get $this->instructions in thankyou.php WooCommerce template?
I already tried using $order->instructions but then an errors appear
Notice: instructions was called incorrectly. Order properties should
not be accessed directly. Backtrace: require('wp-blog-header.php'),
require_once('wp-includes/template-loader.php'),
include('/themes/startup-company/page.php'), the_content,
apply_filters('the_content'), WP_Hook->apply_filters, do_shortcode,
preg_replace_callback, do_shortcode_tag, WC_Shortcodes::checkout,
WC_Shortcodes::shortcode_wrapper, WC_Shortcode_Checkout::output,
WC_Shortcode_Checkout::order_received, wc_get_template,
include('/plugins/woocommerce/templates/checkout/thankyou.php'),
WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see
Debugging in WordPress for more information. (This message was added
in version 3.0.)
So I tried to see what inside $order, and then I see a long vars that doesn't have the text that I set for $this->instructions in WooCommerce Payment Gateway Plugin that I built myself.

You can get all Woocommerce payment methods with WC_Payment_Gateways class. Then you can get the checkout available payment methods and get the related data this way:
$wc_gateways = new WC_Payment_Gateways();
$payment_gateways = $wc_gateways->get_available_payment_gateways();
// Loop through Woocommerce available payment gateways
foreach( $payment_gateways as $gateway_id => $gateway ){
$title = $gateway->get_title();
$description = $gateway->get_description();
$instructions = property_exists( $gateway , 'instructions' ) ? $gateway->instructions : '';
$icon = $gateway->get_icon();
}
Tested and works in Woocommerce 3+
You can also call an instance of your custom Payment gateway Class and use on it the methods and properties like in the code above… Or you can target a specific payment gateway inside the foreach loop using the $gateway_id in an IF statement.

The above example is great! Here's just another option to show the payment methods in radio inputs or dropdown. The shortcode is [display_payment_methods]. Add code to child theme functions.php or use code snippet plugin. Place shortcode in page/post to view on frontend.
add_shortcode('display_payment_methods','display_payment_methods');
function display_payment_methods(){
global $woocommerce;
$available_gatewayz = WC()->payment_gateways->get_available_payment_gateways();
if ( $available_gatewayz ) { ?>
<form id="add_payment_method" method="post">
<div id="payment" class="woocommerce-Payment">
<ul class="woocommerce-PaymentMethods payment_methods methods">
<?php
// Chosen Method.
if ( count( $available_gatewayz ) ) {
current( $available_gatewayz )->set_current();
}
foreach ( $available_gatewayz as $gatewayz ) {
?>
<li class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $gatewayz->id ); ?> payment_method_<?php echo esc_attr( $gatewayz->id ); ?>">
<input id="payment_method_<?php echo esc_attr( $gatewayz->id ); ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gatewayz->id ); ?>" <?php checked( $gatewayz->chosen, true ); ?> />
<label for="payment_method_<?php echo esc_attr( $gatewayz->id ); ?>"><?php echo wp_kses_post( $gatewayz->get_title() ); ?> <?php echo wp_kses_post( $gatewayz->get_icon() ); ?></label>
<?php
if ( $gatewayz->has_fields() || $gatewayz->get_description() ) {
echo '<div class="woocommerce-PaymentBox woocommerce-PaymentBox--' . esc_attr( $gatewayz->id ) . ' payment_box payment_method_' . esc_attr( $gatewayz->id ) . '" style="display: none;">';
$gatewayz->payment_fields();
echo '</div>';
}
?>
</li>
<?php
}}
?>
</ul>
<!-- Enabled Payment Methods Dropdown Select -->
<select name="payment_method" class="select_field">
<option selected="selected" disabled="disabled" value="<?php echo esc_attr( $gatewayz->id ); ?>"><?php echo esc_attr( __( 'Select Payment Method' ) ); ?></option>
<?php
$available_gatewayz = WC()->payment_gateways->get_available_payment_gateways();
// Chosen Method.
if ( count( $available_gatewayz ) ) {
current( $available_gatewayz )->set_current();
}
foreach ( $available_gatewayz as $gatewayz ) {
$option = '<option value="' . esc_attr( $gatewayz->id) . '" ';
$option .= ( esc_attr( $gatewayz->id) == $available_gatewayz ) ? 'selected="selected"' : '';
$option .= '>';
$option .= wp_kses_post( $gatewayz->get_title() ) ;
$option .= '</option>';
echo $option;
}
?>
</select>
<?php
}

Related

How to get and display BACS account details in Woocommerce

I have a very simple idea, but I do not know how to do it in WooCommerce.
In my store I have enabled a few payment options, also paying via bank transfer. But when client chose bank transfer he sees data needed to make a transfer. But after that, there is no option to display that data on thank you page, where everybody looking for that.
There is an easy way to show that data again?
The Bacs account details are stored in wp_options table as most of all Wordpress and Woocommerce settings.
They can be accessed using (which gives a multi-dimensional array of different bank accounts, as you can set many):
$bacs_accounts_info = get_option( 'woocommerce_bacs_accounts');
Normally this details are displayed by default on woocommerce thankyou page and in some customer email notifications…
To display the formatted bank accounts information, I have built this custom function:
// Utility function, to display BACS accounts details
function get_bacs_account_details_html( $echo = true, $type = 'list' ) {
ob_start();
$gateway = new WC_Gateway_BACS();
$country = WC()->countries->get_base_country();
$locale = $gateway->get_country_locale();
$bacs_info = get_option( 'woocommerce_bacs_accounts');
// Get sortcode label in the $locale array and use appropriate one
$sort_code_label = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
if( $type == 'list' ) :
?>
<div class="woocommerce-bacs-bank-details">
<h2 class="wc-bacs-bank-details-heading"><?php _e('Our bank details'); ?></h2>
<?php
$i = -1;
if ( $bacs_info ) : foreach ( $bacs_info as $account ) :
$i++;
$account_name = esc_attr( wp_unslash( $account['account_name'] ) );
$bank_name = esc_attr( wp_unslash( $account['bank_name'] ) );
$account_number = esc_attr( $account['account_number'] );
$sort_code = esc_attr( $account['sort_code'] );
$iban_code = esc_attr( $account['iban'] );
$bic_code = esc_attr( $account['bic'] );
?>
<h3 class="wc-bacs-bank-details-account-name"><?php echo $account_name; ?>:</h3>
<ul class="wc-bacs-bank-details order_details bacs_details">
<li class="bank_name"><?php _e('Bank'); ?>: <strong><?php echo $bank_name; ?></strong></li>
<li class="account_number"><?php _e('Account number'); ?>: <strong><?php echo $account_number; ?></strong></li>
<li class="sort_code"><?php echo $sort_code_label; ?>: <strong><?php echo $sort_code; ?></strong></li>
<li class="iban"><?php _e('IBAN'); ?>: <strong><?php echo $iban_code; ?></strong></li>
<li class="bic"><?php _e('BIC'); ?>: <strong><?php echo $bic_code; ?></strong></li>
</ul>
<?php endforeach; endif; ?>
</div>
<?php
else :
?>
<h2><?php _e( 'Account details', 'woocommerce' ); ?>:</h2>
<table class="widefat wc_input_table" cellspacing="0">
<thead>
<tr>
<th><?php _e( 'Account name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank name', 'woocommerce' ); ?></th>
<th><?php echo $sort_code_label; ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody class="accounts">
<?php
$i = -1;
if ( $bacs_info ) {
foreach ( $bacs_info as $account ) {
$i++;
echo '<tr class="account">
<td>' . esc_attr( wp_unslash( $account['account_name'] ) ) . '</td>
<td>' . esc_attr( $account['account_number'] ) . '</td>
<td>' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '</td>
<td>' . esc_attr( $account['sort_code'] ) . '</td>
<td>' . esc_attr( $account['iban'] ) . '</td>
<td>' . esc_attr( $account['bic'] ) . '</td>
</tr>';
}
}
?>
</tbody>
</table>
<?php
endif;
$output = ob_get_clean();
if ( $echo )
echo $output;
else
return $output;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
POSSIBLE USAGES:
1) In any template or php code you will just use to display this account details:
get_bacs_account_details_html();
2) As a hooked function (where you will set your desired action hook).
Here is an example usage that will display this bank account details in My account order view, for orders that have BACS as payment gateway and an "on hold" status:
add_action( 'woocommerce_view_order', 'display_bacs_account_details_on_view_order', 5, 1 );
function display_bacs_account_details_on_view_order( $order_id ){
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
if( $order->get_payment_method() === 'bacs' && $order->get_status() === 'on-hold' ){
get_bacs_account_details_html();
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
As a shortcode [bacs_account_details]:
add_shortcode( 'bacs_account_details', 'shortcode_bacs_account_details' );
function shortcode_bacs_account_details() {
get_bacs_account_details_html( false );
}
Code goes in function.php file of your active child theme (or active theme). Tested and wok.
Then you can use it in any Wordpress editor of a page, a post or a custom post: [bacs_account_details]
Or in the PHP code: echo do_shortcode('[bacs_account_details]');
Use action on thank you page, In your child functions.php or using code snippets plugin
add_action('woocommerce_thankyou', 'customThankYouFunction');
and in your function write your logic
function customThankYouFunction ($order_id) {
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
}
You can deal with order now
Reference How to get WooCommerce order details

Add a custom multi-select field to admin product options settings in Woocommerce

I have followed this answer How to add more custom field in Linked Product of Woocommerce to add a custom select field to my Linked Product screen in Woocommerce. This new field is meta key is subscription_toggle_product.
It's working fine, but once you have selected a product, you can't delete it (there is no "Empty" option or cross symbol). I haven't got a clue how I can allow the selection to be deselected. I've tried adding an <option> with an empty value, but it hasn't worked.
Here is my code:
// Display the custom fields in the "Linked Products" section
add_action( 'woocommerce_product_options_related', 'woocom_linked_products_data_custom_field' );
// Save to custom fields
add_action( 'woocommerce_process_product_meta', 'woocom_linked_products_data_custom_field_save' );
// Function to generate the custom fields
function woocom_linked_products_data_custom_field() {
global $woocommerce, $post;
$product = wc_get_product( $post->ID );
?>
<p class="form-field">
<label for="subscription_toggle_product"><?php _e( 'Subscription Toggle Product', 'woocommerce' ); ?></label>
<select class="wc-product-search" style="width: 50%;" id="subscription_toggle_product" name="subscription_toggle_product" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-exclude="<?php echo intval( $post->ID ); ?>">
<?php
$product_id = get_post_meta( $post->ID, '_subscription_toggle_product_id', true );
if ( $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select>
</p>
<?php
}
// Function the save the custom fields
function woocom_linked_products_data_custom_field_save( $post_id ){
if (isset($_POST['subscription_toggle_product'])) {
$product_field_type = $_POST['subscription_toggle_product'];
update_post_meta( $post_id, '_subscription_toggle_product_id', $product_field_type );
}
}
This kind of select field only works with a defined multiple attribute and work with an array of values. so you can't use it for a simple ID. If you add to your select field multiple="multiple" attribute it will work.
Also since Woocommerce 3 things have changed:
- There are better hooks to save the data.
- You can now use CRUD Objects and related methods.
The following code will work for multiple product IDs (an array of products IDs):
// Display a custom select field in "Linked Products" section
add_action( 'woocommerce_product_options_related', 'display_linked_products_data_custom_field' );
function display_linked_products_data_custom_field() {
global $product_object, $post;
?>
<p class="form-field">
<label for="subscription_toggle_products"><?php _e( 'Subscription Toggle Products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="subscription_toggle_ids" name="_subscription_toggle_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-exclude="<?php echo intval( $post->ID ); ?>">
<?php
$product_ids = $product_object->get_meta( '_subscription_toggle_ids' );
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select>
</p>
<?php
}
// Save the values to the product
add_action( 'woocommerce_admin_process_product_object', 'save_linked_products_data_custom_field_value', 10, 1 );
function save_linked_products_data_custom_field_value( $product ){
$data = isset( $_POST['_subscription_toggle_ids'] ) ? array_map( 'intval', (array) $_POST['_subscription_toggle_ids'] ) : array();
$product->update_meta_data( '_subscription_toggle_ids', $data );
}
Code goes in function.php file of your active child theme (active theme). Tested and works.

Searchable multiple product select custom field for Woocommerce

I am developing a plugin where I need to display some custom select product. So far I can able to make the option field but how can i save them as option field with comma separated product ids like.
45,78,55,48,
here is an example of searchable multiple select option for WooCommerce product.
Here is my code
function crp_select_products() {
global $post, $woocommerce;
$product_ids = array();
?>
<div class="options_group">
<?php if ( $woocommerce->version >= '3.0' ) : ?>
<p class="form-field">
<label for="related_ids"><?php _e( 'Search Products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="related_ids" name="related_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Select products are for sale product.', 'woocommerce' ) ); ?>
</p>
<?php endif; ?>
</div>
<?php
}
First, there is something missing in your function, to display the saved data in it.
After, this special field need to be displayed inside a form that will have a submit button. So it depends where you are using your function.
Here below is an example displaying that custom field as a custom product setting, save the data and display the saved data in it:
function crp_get_product_related_ids() {
global $post, $woocommerce;
$product_ids = get_post_meta( $post->ID, '_related_ids', true );
if( empty($product_ids) )
$product_ids = array();
?>
<div class="options_group">
<?php if ( $woocommerce->version >= '3.0' ) : ?>
<p class="form-field">
<label for="related_ids"><?php _e( 'Search Products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="related_ids" name="related_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Select products are for sale product.', 'woocommerce' ) ); ?>
</p>
<?php endif; ?>
</div>
<?php
}
add_action( 'woocommerce_product_options_general_product_data', 'add_custom_fied_in_product_general_fields', 20 );
function add_custom_fied_in_product_general_fields() {
global $post, $woocommerce;
crp_get_product_related_ids();
}
add_action( 'woocommerce_process_product_meta', 'process_product_meta_custom_fied', 20, 1 );
function process_product_meta_custom_fied( $product_id ){
if( isset( $_POST['crosssell_ids'] ) ){
update_post_meta( $product_id, '_related_ids', array_map( 'intval', (array) wp_unslash( $_POST['related_ids'] ) ) );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Wordpress - using Ajax on Woocommerce add to cart button shortcodes

I have a pretty strange problem with a custom build I am doing in Wordpress. I am using hooks to overwrite a starter theme's 'add-to-cart' button on a custom page showing products. The weird thing is that when I loop through the add-to-cart button to add quantity options on my products, the original Ajax function disappears. I then implemented another function to add it back in (and cause my custom 'view cart' button's items-in-cart number to update) but although it works in the cart, it doesn't seem to be working for my custom shop page.
I am using this snippet in my header to handle the cart contents:
<?php if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
$count = WC()->cart->cart_contents_count;
?><a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php
if ( $count > 0 ) {
?>
<span class="cart-contents-count"><?php echo esc_html( $count ); ?></span>
<?php
}
?></a>
And here are my two functions in my child-theme functions.php:
/**
* Ensure cart contents update when products are added to the cart via AJAX
*/
function my_header_add_to_cart_fragment( $fragments ) {
ob_start();
$count = WC()->cart->cart_contents_count;
?><a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php
if ( $count > 0 ) {
?>
<span class="cart-contents-count"><?php echo esc_html( $count ); ?></span>
<?php
}
?></a><?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'my_header_add_to_cart_fragment' );
/**
* Add quantity to products in Products Page
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
}
return $html;
}
I think that my second function adding a new add-to-cart button is overwriting the initial Ajax functionality, but everything I try to do to add this functionality back in is not working. I'm not the best at JS/jQuery so it's probably that I'm not implementing my code properly.
Any help with this would be much appreciated.
Need to add another classes to the button i.e add_to_cart_button & ajax_add_to_cart.
Hope this will do for you.

WordPress Custom Menu Widget ==> change to 2-column

I am trying to create a Custom Menu Widget that has two columns (i.e., wherein I can select two different menus and have them display side-by-side within a single sidebar widget).
I found a tutorial on how to create a two column text widget, however I cannot figure out how to edit the Custom Menu widget functions to add and implement an additional menu -- my attempts to create an additional menu variable (i.e., "$menus1" and "$menus2" below) break WordPress ("unexpected T string" error).
Does the "$instance" array have a pre-defined key called 'nav_menu' or are this key and its value created by the "form" function? If the latter, can I define 'nav_menu1' and 'nav_menu2' keys (I tried this before but also got the "unexpected T string" error)?
<?php
/**
* Custom Menu widget copied from default WP Widget Class and adjusted for 2-columns
*/
class SO_ABC_Tag_List_Widget_2col extends WP_Widget {
function __construct() {
$widget_ops = array( 'description' => __('By adding this widget you can select your alphabetical tags menu to display on your website.') );
parent::__construct( 'so_abc_tags_2col', __('SO ABC Tag List 2 col'), $widget_ops );
}
function widget($args, $instance) {
// Get menu
$nav_menu1 = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
$nav_menu2 = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
if ( !$nav_menu )
return;
$instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if ( !empty($instance['title']) )
echo $args['before_title'] . '<i class="icon-tags"></i> ' . $instance['title'] . $args['after_title'];
<div style="float: left; width: 45%">
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu1 ) );
</div>
<div style="float: left; width: 45%"></div>
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu2 ) );
</div>
echo $args['after_widget'];
}
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags( stripslashes($new_instance['title']) );
$instance['nav_menu'] = (int) $new_instance['nav_menu'];
$instance['nav_menu'] = (int) $new_instance['nav_menu'];
return $instance;
}
function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$nav_menu1 = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
$nav_menu2 = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
// Get menus
$menus1 = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
$menus1 = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
// If no menus exists, direct the user to go and create some.
if (( !$menus1 ) AND ( !menus2 )) {
echo '<p>'. sprintf( __('No menus have been created yet. Create some.'), admin_url('nav-menus.php') ) .'</p>';
return;
}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus1 as $menu1 ) {
echo '<option value="' . $menu1->term_id . '"'
. selected( $nav_menu, $menu1->term_id, false )
. '>'. $menu1->name . '</option>';
}
?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus2 as $menu2 ) {
echo '<option value="' . $menu2->term_id . '"'
. selected( $nav_menu, $menu2->term_id, false )
. '>'. $menu2->name . '</option>';
}
?>
</select>
</p>
<?php
}
}
You have html and php code mixed together which certainly would cause an error
if ( !empty($instance['title']) )
echo $args['before_title'] . '<i class="icon-tags"></i> ' . $instance['title'] . $args['after_title'];
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu1 ) );
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu2 ) );
echo $args['after_widget'];
}
Fix that first then see if it still doesnt work.
You also haven't finished changing all the references from menu1 to menu2. And yes you will need to change the the key for $instance and probably get_terms - plus theres some field id stuff in the form function thats duplicated.
But I'm not sure what you want to achieve.
What you're trying to do will output 2 different menus in a single widget.
My suggestion would be to put two menu widgets in the same area and then use css to make them go side by side.

Categories