Forked from bekarice/move-wc-related-items-to-product-tab.php
Created
September 5, 2019 08:46
-
-
Save shamimsdp/69b93abea02ff7849063bd8b98e48d47 to your computer and use it in GitHub Desktop.
Revisions
-
bekarice created this gist
Mar 18, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <?php // only copy if needed /** * If there are upsells or related items for the product, add them in a new tab. * @See https://www.skyverge.com/?p=4242 * * @param string[] $tabs the product tabs * @return string[] maybe updated tabs array */ function sv_wc_maybe_add_upsell_tab( $tabs ) { global $product; // compatibility check for pre / post WC 3.0 $upsells = is_callable( array( $product, 'get_upsell_ids' ) ) ? $product->get_upsell_ids() : $product->get_upsells(); $related = is_callable( array( $product, 'get_cross_sell_ids' ) ) ? $product->get_cross_sell_ids() : $product->get_cross_sells(); // if we have no related items, don't add a new tab if ( empty( $upsells ) && empty( $related ) ) { return $tabs; } // green light! remove the current upsells remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 ); remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); // first, make sure that we're dealing with an array rather than null $new_tabs = is_null( $tabs ) ? array() : $tabs; // now add the upsells back in tabulated formation $new_tabs['upsells'] = array( 'title' => __( 'Related Items', 'woocommerce-upsells-tab' ), 'priority' => 25, 'callback' => 'sv_wc_output_upsells_related_items', ); return $new_tabs; } add_filter( 'woocommerce_product_tabs', 'sv_wc_maybe_add_upsell_tab' ); // Callback to output related products and upsells. function sv_wc_output_upsells_related_items() { woocommerce_upsell_display(); woocommerce_output_related_products(); }