WP e-Commerce "Also bought"
Hej alla kodmyror!
Det är inte ofta jag känner att jag måste be om er hjälp men nu har jag kört fast och skulle behöva er feedback för att komma vidare. Jag håller på att koda en webbsida baserad på Wordpress (3.7.1) tillsammans med ett plugin som heter WP e-Commerce (3.8.12.1) för att få e-handelsfunktioner på webbsidan.
När man är inne på en enskild produkt i webbshoppen så finns det en sektion som jag valt att döpa till "Andra kunder har även beställt..." och där under visas produkter som andra kunder beställt i samband med produkten som besökaren visar just då. Problemet är att under produktbild, namn och pris så syns ingen "Lägg i varukorg"-knapp.
Ni kan se detta live på: http://levarent.se/webbshop/kobold-vr100/
Hur jag än gör så lyckas jag inte få den att skriva ut en knapp.
Se bild nedan för att få en klar bild över hur jag vill att det ser ut.

Om någon känner sig villig att hjälpa mig så finns hela WP e-Commerce på http://getshopped.org/, klicka på "Download Plugin Now" uppe till höger.
Här nedan kommer den kod som infogar hela funktionen "Andra kunder har även beställt...".
Jag misstänker även att ni kommer att behöva ha mer information från mig för att kunna hjälpa mig, t.ex. hur man kallar på "add to cart"-knappen o.s.v.
/**
* Displays products that were bought along with the product defined by $product_id.
* This functionality will be deprecated and be provided by a plugin in a future version.
*/
function wpsc_also_bought( $product_id ) {
global $wpdb;
if ( get_option( 'wpsc_also_bought' ) == 0 ) {
return '';
}
// To be made customiseable in a future release
$also_bought_limit = 4;
$element_widths = 144;
$image_display_height = 134;
$image_display_width = 134;
// Filter will be used by a plugin to provide 'Also Bought' functionality when this is deprecated from core.
// Filter is currently private and should not be used by plugin/theme devs as it may only be temporary.
$output = apply_filters( '_wpsc_also_bought', '', $product_id );
if ( ! empty( $output ) ) {
return $output;
}
// If above filter returns output then the following is ignore and can be deprecated in future.
$also_bought = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A );
if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) {
$output .= '<h2 class="prodtitles wpsc_also_bought">' . __( 'Andra kunder har även beställt...', 'wpsc' ) . '</h2>';
$output .= '<div class="wpsc_also_bought clearfix">';
foreach ( $also_bought as $also_bought_data ) {
$output .= '<div class="wpsc_also_bought_item" style="width: ' . $element_widths . 'px;">';
if ( get_option( 'show_thumbnails' ) == 1 ) {
$image_path = wpsc_the_product_thumbnail( $image_display_width, $image_display_height, $also_bought_data['ID'] );
if ( $image_path ) {
$output .= '<a href="' . esc_attr( get_permalink( $also_bought_data['ID'] ) ) . '" class="preview_link" rel="' . esc_attr( sanitize_html_class( get_the_title( $also_bought_data['ID'] ) ) ) . '">';
$output .= '<img src="' . esc_attr( $image_path ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" />';
$output .= '</a>';
} else {
if ( get_option( 'product_image_width' ) != '' ) {
$width_and_height = 'width="' . $image_display_height . '" height="' . $image_display_height . '" ';
} else {
$width_and_height = '';
}
$output .= '<img src="' . WPSC_CORE_THEME_URL . '/wpsc-images/noimage.png" title="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" alt="' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . '" id="product_image_' . $also_bought_data['ID'] . '" class="product_image" ' . $width_and_height . '/>';
}
}
$output .= '<p class="product-name"><a class="wpsc_product_name" href="' . get_permalink( $also_bought_data['ID'] ) . '">' . get_the_title( $also_bought_data['ID'] ) . '</a></p>';
if ( ! wpsc_product_is_donation( $also_bought_data['ID'] ) ) {
// Ideally use the wpsc_the_product_price_display() function here but needs some tweaking
$price = get_product_meta( $also_bought_data['ID'], 'price', true );
if ( ! empty( $special_price ) ) {
$output .= '<span style="text-decoration: line-through;">' . wpsc_currency_display( $price ) . '</span>';
} else {
$output .= wpsc_currency_display( $price );
}
}
$output .= '</div>';
}
$output .= '</div>';
}
return $output;
}
Edit: Koden ovan finns på rad 87 i filen display.functions.php i mappen wpsc-includes i mappen för pluginet WP e-Commerce.