Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell you How to capture all of the content that Dokan adds to the Shipping product tab?
Guys if you are new in WordPress or in WooCommerce then please check the below links for some good tutorials:
To capture all of the content that Dokan adds to the Shipping product tab and make it reusable via a shortcode, you can use WordPress hooks to fetch the content and create a shortcode for rendering it anywhere on the product page.
Here’s how to achieve this:
Step 1: Capture Dokan Shipping Tab Content
Dokan adds content to the Shipping tab using the dokan_shipping_tab_content
action. You can hook into this action to capture the content.
Code to Capture Content:
Add the following to your theme’s functions.php
or a custom plugin:
function capture_dokan_shipping_tab_content() { ob_start(); // Start output buffering do_action('dokan_shipping_tab_content'); // Execute the action that outputs Dokan's shipping content return ob_get_clean(); // Get the buffered content }
This function captures the content that Dokan adds to the shipping tab.
Step 2: Create a Shortcode to Display the Content
Now, wrap the captured content in a shortcode so you can display it anywhere.
Add the Shortcode:
function dokan_shipping_tab_shortcode() { return capture_dokan_shipping_tab_content(); // Use the capturing function } add_shortcode('dokan_shipping_tab', 'dokan_shipping_tab_shortcode');
This shortcode, [dokan_shipping_tab]
, can be used anywhere on the product page to display the shipping content.
Step 3: Display the Shortcode on the Product Page
You can use the shortcode [dokan_shipping_tab]
in any of the following ways:
- Product Description: Add the shortcode directly to the product description or short description.
- Custom Hook: Insert the shortcode at a specific location on the product page using a WooCommerce hook.
Example: Use a WooCommerce Hook
Add this to your functions.php
to insert the shortcode at a custom location:
add_action('woocommerce_after_single_product_summary', 'display_dokan_shipping_tab_content', 15); function display_dokan_shipping_tab_content() { echo do_shortcode('[dokan_shipping_tab]'); }
This will display the Dokan shipping tab content below the product summary.
Step 4: Verify and Style the Output
After implementing the above steps:
- Test the shortcode in your product description, WooCommerce hooks, or anywhere else.
- Style the output using custom CSS if needed.
Optional: Conditional Display Based on Vendor
If you want the content to display only for Dokan-enabled vendors, wrap the shortcode output with a conditional check:
function dokan_shipping_tab_shortcode() { if (dokan_is_seller_page()) { // Check if the product belongs to a vendor return capture_dokan_shipping_tab_content(); } return ''; // Return nothing if not a vendor product } add_shortcode('dokan_shipping_tab', 'dokan_shipping_tab_shortcode');
Result
Guys now we have a shortcode [dokan_shipping_tab]
that displays all the content Dokan adds to the shipping tab. This shortcode can be used anywhere on the product page or in custom WooCommerce hooks to control its placement.
Let me know if you need further assistance! ????
Guys if you will have any kind of query then feel free to comment below.
Thanks
Jassa