Add a link to the product page woocomerce

Viewed 20

I have made a custom field in the product card and displayed it in the catalogue, but the problem is that there is no link to go to the product card. I would appreciate any help.

Here is the code for adding a field in the product card

    // Field Short name
add_action( 'woocommerce_product_options_general_product_data', 'shorttitle_custom_general_fields' );
add_action( 'woocommerce_process_product_meta', 'shorttitle_custom_general_fields_save' );

function shorttitle_custom_general_fields() {
    global $woocommerce, $post;
    echo '<div class="options_group">';
    woocommerce_wp_text_input( 
        array( 
            'id' => 'shorttitle_field', 
            'label' => __( 'Краткое название', 'woocommerce' ), 
            //'desc_tip' => 'true',
            //'description' => __( 'Краткое название', 'woocommerce' ),
            'type' => 'html'
        )
    );

    echo '</div>';
}

function shorttitle_custom_general_fields_save( $post_id ){

    // Text Field
    $woocommerce_text_field = $_POST['shorttitle_field'];
    if( !empty( $woocommerce_text_field ) )
        update_post_meta( $post_id, 'shorttitle_field', esc_attr( $woocommerce_text_field ) );

}

This is the code for displaying this field on the catalogue page

    // Change the output of the product header (in the catalogue)

remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title' );
add_action( 'woocommerce_shop_loop_item_title', 'custom_woocommerce_template_loop_product_title', 99 );

function custom_woocommerce_template_loop_product_title() {
    global $post;

    $product = wc_get_product( $post->ID );
    $title = get_post_meta( $post->ID, 'shorttitle_field', true );
    if( $title ) {
        echo '<h2 class="woocommerce-loop-product__title">' . esc_html( $title ) . '</h2>';
    } else {
        echo '<h2 class="woocommerce-loop-product__title">' . esc_html( $product->get_title() ) . '</h2>';
        
    }
}

Page https://www.krisstyle.com.ua/shop/

0 Answers
Related