php – How to display Woocommerce cross-sells in single product tabs

Question

I’m trying to display cross sells using the following function:

woocommerce_cross_sell_display();

This function is part of Woocommerce default functions, and it suppose to work. Meanwhile I receive nothing (No error, no visual results).

Here is how I tried to display cross sells in Woocommerce tabs:

//Add custom tabs filter
add_filter('woocommerce_product_tabs', 'add_new_default_product_tab' );
function add_new_default_product_tab( $tabs ) {

    global $product;

    // set the new priority to the "reviews" tab
    $tabs['reviews']['priority'] = 20;

    // gets the value to use as the title and slug of the new tab
    $custom_tab_title = "אביזרים";
    $custom_tab_title2 = "אביזרים משלימים";

    // if the custom field is set, it adds the new tab
    if ( ! empty($custom_tab_title) ) {
        $tabs['awp-' . sanitize_title('props')] = array(
            'title' => 'אביזרים',
            'callback' => 'awp_custom_woocommerce_tabs',
            'priority' => 5
        );
    }
    if ( ! empty($custom_tab_title) ) {
        $tabs['awp-' . sanitize_title('additional-props')] = array(
            'title' => 'אביזרים משלימים',
            'callback' => 'awp_custom_woocommerce_tabs2',
            'priority' => 10
        );
    }
    return $tabs;
}
 
    //Callback to display upsells (WORKS)
    
    function awp_custom_woocommerce_tabs($key, $tab) {
         woocommerce_upsell_display( 3,3 );
    }
    
    
    //Callback to display cross sells (Doesn't work)
    
    function awp_custom_woocommerce_tabs2($key, $tab) {
        woocommerce_cross_sell_display();
    }

Also tried displaying cross sells just to test if it works even when it’s not inside the tabs. It doesn’t, I’m lost here.

remove_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_cross_sell_display' );
add_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_cross_sell_display', 15);

How can I display cross sells on tabs in single product page? And what is affecting cross sells visibility?

0
Yotam Dahan 2 years 2021-04-08T09:54:29-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse