skip to Main Content

I was wondering how to override the default product bundles permalink function. I use the plugin Woocommerce Product bundles for this.

The default function from “class-wc-bundled-item” is this:

/**
 * Item permalink.
 *
 * @since  5.5.0
 *
 * @return string
 */
public function get_permalink() {
    /**
     * 'woocommerce_bundled_item_permalink' filter.
     *
     * @param  string           $permalink
     * @param  WC_Bundled_Item  $this
     */
    return apply_filters( 'woocommerce_bundled_item_permalink', $this->is_visible() && $this->product->is_visible() ? $this->product->get_permalink() : '', $this );
}

I want to override this function in my functions.php file. Unfortunately it returns the permalink of the product bundle and not from the linked (underlaying) product.

This is the code i tried:

add_filter( 'woocommerce_bundled_item_permalink', 'get_bundle_product_permalink' );
function get_bundle_product_permalink() {
    return get_permalink();
}

What am i doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    Something like this?

    /* Set the visibility function */
    function filter_woocommerce_product_is_visible( $visible, $this_get_id ) {
        return apply_filters( 'woocommerce_bundled_item_permalink', '__return_true' );
    }; 
    add_filter( 'woocommerce_product_is_visible', 'filter_woocommerce_product_is_visible', 10, 2 ); 
    

  2. add_filter( 'woocommerce_product_is_visible', '__return_true' );
    

    Try this code snippet to bypass is_visble check

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search