Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionSo what my clients wants is on the shop page, on each product there to be a second button next to the shop button. This button should lead to a custom for each product pdf file, that the client can download wihtout the need to enter the exact product page itself. I am new to developing and this is a bit hard for me so if you guys and girls can help me i will be extremely thankful :)
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionSo what my clients wants is on the shop page, on each product there to be a second button next to the shop button. This button should lead to a custom for each product pdf file, that the client can download wihtout the need to enter the exact product page itself. I am new to developing and this is a bit hard for me so if you guys and girls can help me i will be extremely thankful :)
Code is tested with 2019 theme. Open the functions.php file of your active theme and drop this code at end of the file.
add_action( 'woocommerce_after_shop_loop_item', 'wpse2019_add_pdf_download_button', 10 );
function wpse2019_add_pdf_download_button() {
global $product;
if( $product ) {
printf( '<a href="%s" class="pdf-button button btn" role="button">%s</a>', "YOUR PDF LINK HERE", __( 'DWONLOAD PDF', 'text-domain' ) );
}
}
default add to cart and select options buttons are adding via woocommerce_after_shop_loop_item hook (source: templates/archive-product.php). I use the same hook and add the 2nd custom button. You will replace YOUR PDF LINK HERE with your PDF link.
If you will add different PDF file for every product, you will use the custom field logic. You can use the WordPress native custom field option or some free plugin like ACF/PODs/CMB2 etc
Assume your custom field would be wc_product_pdf_file. Then you can try this code
add_action( 'woocommerce_after_shop_loop_item', 'wpse2019_add_pdf_download_button', 10 );
function wpse2019_add_pdf_download_button() {
global $product;
if( $product ) {
$pdf_link = get_post_meta( $product->get_id(), 'wc_product_pdf_file', true );
if( ! empty( $pdf_link ) ) {
printf( '<a href="%s" class="pdf-button button btn" role="button">%s</a>', $pdf_link, __( 'DWONLOAD PDF', 'text-domain' ) );
}
}
}
get_post_meta function is fetching the post meta data. $product->get_id() is giving the current product ID.
Note: Before editing the file, you keep a backup of your theme.