Woocommerce product tabs (show other products) - wordpress

I am using woo commerce in my wordpress store online, I got a requirement that when a product is clicked and we navigate to the product detail page. I need to show the tabs into the product page like in the link
http://www.designbyhumans.com/shop/t-shirt/men/wolf-i/17011/
In this link two additional tabs are shown
1. Phone Cases
2. Art prints
Is there any way to achieve this is woo commerce?
Please help.

You can add custom tabs using woocommerce filters
The below code adds an extra tab called 'Product Description'.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Product Description', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
}
function woo_new_product_tab_content() {
// The new tab content
$prod_id = get_the_ID();
echo '<p>'.get_post_meta($prod_id,'product_description',true).'</p>';
}
You would need to fetch the product data into these tabs. In the above example data from a custom field(product_description) is fetched into the tab.

Related

Adding extra tabs to woocommerce single product

Hi i wish to add extra tabs to woocommerce single product. I have seen the code below which works but every product has the same tab, is there a way where i can select products where the tab would show as i want the same info on multiple products but not all products.
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}

add_menu_page item show to Editor Role Wordpress

I've been trying to add a menu to my WP Dashboard which I already accomplished. But now I want to show this menu to the Editor role as well as the administrator.
Here is my code
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {
add_menu_page( 'Instagram test', 'Instagram test', 'read', 'admin.php?page=sb-instagram-feed', '', 'dashicons-welcome-widgets-menus', 90 );
}
So far it works, but only for my administrator user, not to my Editors users.
I've read about the capabilities and that is why I put the read value on the function above.
How can I also show this menu to my Editors users?
Here is a screenshot, my custom menu is Instagram test.
Admin's Dashboard
Editor's Dashboard
While I can't attest to why read isn't working - generally if you want to limit something by user roles, you can put in the slug for the role. If you read the source for add_menu_page() it will actually run the capability through current_user_can which accepts a role slug as well.
I would replace read with editor and see what that gets you. It will also work for admins since it propagates down the list and administrators all have the editor, contributor, etc. "capabilities".
Edit: It appears you have the Instagram Feed plugin installed which will be conflicting with your custom plugin. The code from that plugin shows the sb-instagram-feed page belongs to that plugin:
function sb_instagram_menu() {
add_menu_page(
__( 'Instagram Feed', 'instagram-feed' ),
__( 'Instagram Feed', 'instagram-feed' ),
'manage_options',
'sb-instagram-feed',
'sb_instagram_settings_page'
);
add_submenu_page(
'sb-instagram-feed',
__( 'Settings', 'instagram-feed' ),
__( 'Settings', 'instagram-feed' ),
'manage_options',
'sb-instagram-feed',
'sb_instagram_settings_page'
);
}
add_action('admin_menu', 'sb_instagram_menu');
And that plugin requires manage_options, an administrator only capability. You'll need to not link to the page that other plugin makes, or deactivate that plugin.
Edit 2: Note that editing plugin files directly usually isn't a great practice as any changes you make will be overwritten when the plugin is updated. You might be able to unhook the current admin menu for it and hook in your custom one.
// Remove Existing Menu
remove_action( 'admin_menu', 'sb_instagram_menu' );
// Add Custom Menu
add_action( 'admin_menu', 'custom_sb_instagram_menu');
function custom_sb_instagram_menu() {
add_menu_page(
'Instagram Test',
'Instagram Test',
'editor',
'sb-instagram-feed',
'sb_instagram_settings_page'
);
add_submenu_page(
'sb-instagram-feed',
'Test Settings',
'Test Settings',
'editor',
'sb-instagram-feed',
'sb_instagram_settings_page'
);
}
This is the correct one for Admin and Editor role both.
add_menu_page( 'Transcoding Mp3', 'Transcoding Mp3', 'edit_pages', 'transcoding_mp3', 'transcoding_mp3_fun', '', 90 );
function transcoding_mp3_fun() {
$currentusr = wp_get_current_user();
$idcur = $currentusr->data->ID;
$namecur = $currentusr->data->user_login;
echo 'This is editor id = '. $namecur;
}

Add secondary attributes tab to woocommerce

I need to add another tab to product tabs section of woocommerce with the name of features and it's content fills just like attributes section. the source be same but data store in separate meta data and show it in another tab in product page view section.
any Idea how should to do this?
thank you in advance
Here is my code
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['featurestab'] = array(
'title' => __( 'Features', 'woocommerce' ),
'priority' => 15,
'callback' => 'features_tab_content');
return $tabs;
}
function features_tab_content() {
echo 'Your product ('.get_the_ID().') features.';
}

How can I customize a template for custom Woocommerce fields?

I created some fields with Advanced Custom Fields for the woocommerce orders. I want to custom the template orders.php to show the ACF fields in the orders table. These fields includ images. I found no plugin or hook to do this for the orders users page.
This hook below shows how to add a button to orders action. What I need is add a column to show a custom field.
function sv_add_my_account_order_actions( $actions, $order ) {
$actions['help'] = array(
// adjust URL as needed
'url' => '/contact/?&order=' . $order->get_order_number(),
'name' => __( 'Get Help', 'my-textdomain' ),
);
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'sv_add_my_account_order_actions', 10, 2 );
Thanks!

how do i add the post list to a newly admin panel in wordpress?

I have created a new sub menu for a custom post type in wordpress admin, and I would like to add the a modified list of posts in there, i accordance to the newly variables that i have in my database; is there a function in wordpress to display the post lists? or do i have to do it manually?
add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
add_submenu_page( 'edit.php?post_type=product', __( 'My product list', 'zeeneo-tenders' ), __( 'My product list', 'woo-tenders' ), 'manage_options', 'my-products', 'my_plugin_options');
}
function my_plugin_options() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
echo "<h2>" . __( 'My products list', 'zeeneo-tenders' ) . "</h2>";
// Here is the code to display the list of posts in this new panel
}
WordPress doesn't have wp_dropdown_posts just like it has wp_dropdown_categories and wp_dropdown_users.
It has to be made by hand with get_posts or WP_Query, loop the results and make the <select><option>. For your use case, I think you'll need to use the Custom Fields parameters.
You can find a sample code at WPSE: Dropdown list of a custom post type.

Resources