Champ personnalisés avec Dukapress (Créer un compte)

  • Statut : non résolu
7 sujets de 1 à 7 (sur un total de 7)
  • Auteur
    Messages
  • #495560
    Cedric C.
    Participant
    Maître WordPress
    612 contributions

    Bonjour,

    Suite à un post précédent, j’essaye de personnaliser Dukapress avec des champs personnalisés.

    J’ai réussi à le faire pour la fiche produit, mais j’essaye maintenant d’importer mes champs personnalisés sur la page catalogue. J’ai donc essayé de modifier le fichier dp-products.php de ce plugin.

    Tout bonnement, j’ai essayé d’introduire la fonction :

    $content .= get_post_meta($post->ID, « monchamp », true);

    vers la ligne 350 du fichier mais rien ne s’affiche.

    Je comprends donc que la fonction des champs personnalisés n’est pas reconnue sur cette page. J’aimerais savoir comment pouvoir la faire reconnaître.

    Merci de votre aide

    #772925
    Guy
    Participant
    Maître WordPress
    14817 contributions

    le $post->ID est il valide?

    #772926
    Cedric C.
    Participant
    Maître WordPress
    612 contributions

    Mes connaissances en php étant mince, que cela veut-il dire ?

    Si je clique sur la vignette du produit affiché, alors j’arrive normalement sur la fiche produit, et je fais appel dans cette fiche produit au même champ personnalisé qui s’affiche correctement.

    Voici le code de ma fameuse page dp-product.php (au cas où ça puisse répondre à votre question :

    <?php
    /*
    * This file handles the functions related to products and shortcode for product display and grid display
    */


    /**
    * This function outputs the Product detail
    *
    */
    function dpsc_get_product_details($product_id) {
    global $wpdb;
    $dp_shopping_cart_settings = get_option('dp_shopping_cart_settings');
    $all_custom_fields = get_post_custom($product_id);
    if (is_numeric($all_custom_fields['price'][0])) {
    $custom_fields_output = array();

    $custom_fields_output['start'] = '<form id="dpsc_product_form_' . $product_id . '" name="dpsc_product_form_' . $product_id . '" class="product_form" action="" method="post" enctype="multipart/form-data">‘;
    if($dp_shopping_cart_settings[‘dp_shop_mode’] != ‘inquiry’) {
    if (is_numeric($all_custom_fields[‘new_price’][0])) {
    $product_price = $all_custom_fields[‘new_price’][0];
    $custom_fields_output[‘price’] = ‘<span class="dpsc_price">‘ . __(‘Price:’, »dp-lang ») . ‘ ‘ . $dp_shopping_cart_settings[‘dp_currency_symbol’] . ‘<span class="was">‘ . $all_custom_fields[‘price’][0] . ‘</span> <span class="is">‘ . $all_custom_fields[‘new_price’][0] . ‘</span></span>‘;
    }
    else {
    $product_price = $all_custom_fields[‘price’][0];
    $custom_fields_output[‘price’] = ‘<span class="dpsc_price">‘ . __(‘Price:’, »dp-lang ») . ‘ ‘ . $dp_shopping_cart_settings[‘dp_currency_symbol’] . ‘<span class="is">‘ . $all_custom_fields[‘price’][0] . ‘</span></span>‘;
    }
    }
    $item_weight =  »;
    if (isset ($all_custom_fields[‘item_weight’][0])) {
    $item_weight =  »;
    }

    $custom_fields_output[‘end’] = $item_weight . ‘
    <div class="dpsc_update_icon" id="dpsc_update_icon_' . $product_id . '"><img src="' . DP_PLUGIN_URL . '/images/update.gif" alt="update" /></div>



    </form>‘;

    if (isset ($all_custom_fields[‘dropdown_option’][0])) {
    $dropdown_content .= ‘<div class="dpsc_variation_main">‘;
    $get_vars = explode(‘||’,$all_custom_fields[‘dropdown_option’][0]);
    $div_var_id = 0;
    foreach ($get_vars as $get_var) {
    $pro_vars = explode(‘|’, $get_var);
    $vari_name = $pro_vars[0];
    $dropdown_content .= ‘<div id="dpsc_variation_'.$div_var_id.'" class="dpsc_variation"><span class="dpsc_variation">‘ . __(‘Select’) . ‘ ‘.__($vari_name).’ </span>‘;
    $pro_vars = array_slice($pro_vars, 1);
    $dropdown_content .=  »;
    foreach ($pro_vars as $pro_var) {
    $get_var = explode(‘;’,$pro_var);
    $var_price_text =  »;
    if (isset($get_var[1])) {
    $var_price = floatval($get_var[1]);
    $var_price_display = number_format(floatval($get_var[1]),2);
    if ($var_price != 0.00 && ($dp_shopping_cart_settings[‘dp_shop_mode’] != ‘inquiry’)) {
    $var_price_text = ‘ ( ‘ . $dp_shopping_cart_settings[‘dp_currency_symbol’] . $var_price_display.’ ) ‘;
    }
    }
    $dropdown_content .=  ».$get_var[0].$var_price_text. »;
    }
    $dropdown_content .= ‘</div><div class="clear"></div>‘;
    $div_var_id++;
    }
    $dropdown_content .= ‘</div><div class="clear"></div>‘;
    $custom_fields_output[‘dropdown’] = $dropdown_content;
    if($dp_shopping_cart_settings[‘dp_shop_mode’] != ‘inquiry’) {
    $custom_fields_output[‘end’] = ‘
    var flag=0; //whether ie or ff
    if(navigator.appName== »Microsoft Internet Explorer »){initialCost=SalePriceLabel1.value;flag=1;}
    //change value in variant and get final price
    function getFinalPrice_’ . $product_id . ‘(){
    try{
    var drpdown;
    var drpdownID;
    var selIndex;
    var selText;
    var costDiff;
    //–
    var SalePriceLabel1=document.getElementById(« dpsc_actual_price_’ . $product_id . ‘ »);
    var initialCost=SalePriceLabel1.value;
    var SalePriceLabel=document.getElementById(« dpsc_new_product_price_’ . $product_id . ‘ »);
    var SalePrice=initialCost;//works diffent for IE and FF
    //var promoOff=parseFloat(document.getElementById(« ctl00_ctl00_Body_PageContent_uxPromoPerc »).value);
    //stores sale price; which is to be updated
    //now getting the price from dropdowns
    var check=document.dpsc_product_form_’ . $product_id . ‘.elements;
    for(i=0;i0){
    totalLen=String(SalePrice).length;
    valAfterDec=String(SalePrice).substring(desPos+1,totalLen);
    if(valAfterDec.length==1){SalePrice=String(SalePrice)+ »0″;}
    }
    if(String(SalePrice).indexOf(« . »)<0){SalePrice=String(SalePrice)+".00";}
    //END [Nibha : 20080229] Patch added for missing .00 in case of perfectly round numbers.
    }
    }
    }
    if(flag==0){SalePriceLabel.textContent=SalePrice;}
    if(flag==1){SalePriceLabel.innerText=SalePrice;}
    document.dpsc_product_form_' . $product_id . '.dpsc_price_updated.value=SalePrice;
    }catch(ex){}}
    ‘ . $custom_fields_output[‘end’] . ‘
    getFinalPrice_’ . $product_id . ‘();
    ‘;
    $custom_fields_output[‘final_price’] = ‘<p class="dpsc_price">Price: ‘ . $dp_shopping_cart_settings[‘dp_currency_symbol’] . ‘<span id="dpsc_new_product_price_' . $product_id . '">‘ . $product_price . ‘</span></p>‘;
    }
    }

    $attachment_images =&get_children(‘post_type=attachment&post_status=inherit&post_mime_type=image&post_parent=’ . $product_id);
    if (is_array($attachment_images) && count($attachment_images) != 0) {
    $image_effect = $dp_shopping_cart_settings[‘image_effect’];
    $image_content =  »;
    switch ($image_effect) {
    case ‘mz_effect’:
    $image_content = dp_pnj_mz_effect($attachment_images, $product_id);
    break;

    case ‘mzp_effect’:
    $image_content = dp_pnj_mz_effect($attachment_images, $product_id);
    break;

    case ‘lightbox’:
    $image_content = dp_pnj_lightbox_effect($attachment_images, $product_id);
    break;

    case ‘no_effect’:
    $image_content = dp_pnj_no_effect($attachment_images, $product_id);
    break;

    case ‘jqzoom_effect’:
    $image_content = dp_pnj_jqzoom_effect($attachment_images, $product_id);
    break;

    default:
    break;
    }
    $custom_fields_output[‘image_output’] = $image_content;
    }

    $in_stock =  »;
    $available_in_stock = TRUE;
    if($dp_shopping_cart_settings[‘dp_shop_inventory_active’] === ‘yes’ && isset($all_custom_fields[‘currently_in_stock’][0])) {
    if($dp_shopping_cart_settings[‘dp_shop_inventory_stocks’] === ‘yes’ && $all_custom_fields[‘currently_in_stock’][0] > 0) {
    $custom_fields_output[‘end’] =  » . $custom_fields_output[‘end’];
    $in_stock = ‘<span class="dpsc_in_stock">‘ . __(‘Currently in Stock’, »dp-lang ») . ‘</span>‘;
    }
    elseif ($dp_shopping_cart_settings[‘dp_shop_inventory_soldout’] === ‘yes’ && $all_custom_fields[‘currently_in_stock’][0] < 1) {
    $in_stock = '<span class="dpsc_in_stock_sold_out">‘ . __(‘Out of Stock’, »dp-lang ») . ‘</span>‘;
    $available_in_stock = FALSE;
    }
    }
    $custom_fields_output[‘in_stock’] = $in_stock;

    $value_atc = __(‘Add to Cart’, »dp-lang »);
    if($dp_shopping_cart_settings[‘dp_shop_mode’] === ‘inquiry’) {
    $value_atc = __(‘Inquire’, »dp-lang »);
    }
    $disabled_add_to_cart =  »;
    if (!$available_in_stock) {
    $disabled_add_to_cart = ‘disabled= »disabled »‘;
    }
    $custom_fields_output[‘add_to_cart’] =  »;


    return $custom_fields_output;
    }
    return FALSE;
    }

    /**
    * The functions below handle the image effect output
    *
    */
    function dp_pnj_mz_effect($attachment_images, $product_id) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    $output = ‘<div class="dpsc_image_section">‘;
    $output .= ‘<div class="dpsc_image_tab">‘;
    $output .= ‘<ul class="dpsc_tabs">‘;
    $count = 0;
    foreach ($attachment_images as $image) {
    if ($count === 0) {
    $main_image = $image->guid;
    }
    $output .= ‘<li><a class="dpsc_thumb_tab" id="' . $product_id . '">guid . ‘ »><img>guid . ‘&w=’ . $dp_shopping_cart_settings[‘t_w’] . ‘&h=’ . $dp_shopping_cart_settings[‘t_h’] . ‘&zc=1″ alt »thumbnail »/></a></li>‘;
    $count++;
    }
    $output .= ‘</ul>‘;
    $output .= ‘</div>‘;
    $output .= ‘<div class="dpsc_main_image main_' . $product_id . '">‘;
    $output .= ‘<a href="' . $main_image . '" class="MagicZoom" id="zoom1" rel="show-title: false; zoom-fade: true; zoom-position: inner; thumb-change: mouseover"><img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['m_w'] . '&h=' . $dp_shopping_cart_settings['m_h'] . '&zc=1" alt="zoom" /></a>‘;
    $output .= ‘</div>‘;
    $output .= ‘</div>‘;
    return $output;
    }

    function dp_pnj_jqzoom_effect($attachment_images, $product_id) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    $output = ‘<div class="dpsc_image_section">‘;
    $output .= ‘<div class="dpsc_image_tab">‘;
    $output .= ‘<ul class="dpsc_tabs">‘;
    $count = 0;
    foreach ($attachment_images as $image) {
    if ($count === 0) {
    $main_image = $image->guid;
    }
    $output .= ‘<li><a class="dpsc_thumb_tab" id="' . $product_id . '">guid . ‘ »><img>guid . ‘&w=’ . $dp_shopping_cart_settings[‘t_w’] . ‘&h=’ . $dp_shopping_cart_settings[‘t_h’] . ‘&zc=1″ alt= »thumbnail » /></a></li>‘;
    $count++;
    }
    $output .= ‘</ul>‘;
    $output .= ‘</div>‘;
    $output .= ‘<div class="dpsc_main_image main_' . $product_id . '">‘;
    $output .= ‘<a href="' . $main_image . '" title="image" class="dp_jqzoom"><img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['m_w'] . '&h=' . $dp_shopping_cart_settings['m_h'] . '&zc=1" alt="image" /></a>‘;
    $output .= ‘</div>‘;
    $output .= ‘</div>‘;
    return $output;
    }

    function dp_pnj_lightbox_effect($attachment_images, $product_id) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    $output = ‘<div class="dpsc_image_section">‘;
    $output .= ‘<div class="dpsc_image_tab">‘;
    $output .= ‘<ul class="dpsc_tabs">‘;
    $count = 0;
    foreach ($attachment_images as $image) {
    if ($count === 0) {
    $main_image = $image->guid;
    }
    $output .= ‘<li><a class="dpsc_thumb_tab fancybox" id="' . $product_id . '" rel="imgGroup">guid . ‘ »><img>guid . ‘&w=’ . $dp_shopping_cart_settings[‘t_w’] . ‘&h=’ . $dp_shopping_cart_settings[‘t_h’] . ‘&zc=1″ alt= »image » /></a></li>‘;
    $count++;
    }
    $output .= ‘</ul>‘;
    $output .= ‘</div>‘;
    $output .= ‘<div class="dpsc_main_image main_' . $product_id . '">‘;
    $output .= ‘<a href="' . $main_image . '" class="fancybox theProdMedia theProdMedia_alt" rel="imgGroup"><img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['m_w'] . '&h=' . $dp_shopping_cart_settings['m_h'] . '&zc=1" alt="image" /></a>‘;
    $output .= ‘</div>‘;
    $output .= ‘</div>‘;
    return $output;
    }

    function dp_pnj_no_effect($attachment_images, $product_id) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    $output = ‘<div class="dpsc_image_section">‘;
    $output .= ‘<div class="dpsc_image_tab">‘;
    $output .= ‘<ul class="dpsc_tabs">‘;
    $count = 0;
    foreach ($attachment_images as $image) {
    if ($count === 0) {
    $main_image = $image->guid;
    }
    $output .= ‘<li><a class="dpsc_thumb_tab" id="' . $product_id . '">guid . ‘ »><img>guid . ‘&w=’ . $dp_shopping_cart_settings[‘t_w’] . ‘&h=’ . $dp_shopping_cart_settings[‘t_h’] . ‘&zc=1″ alt= »image » /></a></li>‘;
    $count++;
    }
    $output .= ‘</ul>‘;
    $output .= ‘</div>‘;
    $output .= ‘<div class="dpsc_main_image main_' . $product_id . '">‘;
    $output .= ‘<img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['m_w'] . '&h=' . $dp_shopping_cart_settings['m_h'] . '&zc=1" alt="thumbnail" />‘;
    $output .= ‘</div>‘;
    $output .= ‘</div>‘;
    return $output;
    }

    /**
    * Shortcode to display product
    *
    */
    add_shortcode(‘dpsc_display_product’, ‘dpsc_pnj_display_product_name’);
    function dpsc_pnj_display_product_name($atts, $content = null) {
    $product_id = get_the_ID();
    $output = dpsc_get_product_details($product_id);
    $content .= ‘<div class="dpsc_product_main_container">‘;
    $content .= ‘<div class="dpsc_image_container">‘;
    $content .= $output[‘image_output’];
    $content .= ‘</div>‘;
    $content .= ‘<div class="dpsc_content_container">‘;
    if ($output[‘final_price’]) {
    $content .= $output[‘final_price’];
    }
    else {
    $content .= $output[‘price’];
    }
    $content .= $output[‘in_stock’];
    $content .= $output[‘start’];
    $content .= $output[‘dropdown’];
    $content .= $output[‘add_to_cart’];
    $content .= $output[‘end’];
    $content .= ‘</div>‘;
    $content .= ‘</div><div class="clear"></div>‘;
    return $content;
    }

    /**
    * Shortcode to display product in grid views
    *
    */
    add_shortcode(‘dpsc_grid_display’, ‘dpsc_pnj_grid_display’);
    function dpsc_pnj_grid_display($atts, $content=null) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    extract(shortcode_atts( array(
    ‘category’ => ‘1’,
    ‘total’ => ’12’,
    ‘column’ => ‘3’,
    ‘per_page’ =>  »,
    ‘type’ => ‘post’,
    ‘order’ => ‘DESC’
    ), $atts));

    if (!empty($per_page)) {
    $pagenum = isset($_GET[‘dpage’]) ? $_GET[‘dpage’] : 1;
    $count = count(get_posts(‘numberposts=’ . $total . ‘&post_type=’ . $type . ‘&meta_key=price&category=’ . $category));
    $page_links = paginate_links( array(
    ‘base’ => add_query_arg( ‘dpage’, ‘%#%’ ),
    ‘format’ =>  »,
    ‘prev_text’ => __(‘«’),
    ‘next_text’ => __(‘»’),
    ‘total’ => ceil($count / $per_page),
    ‘current’ => $pagenum
    ));
    $post_offset = ($pagenum-1) * $per_page;
    $offset = ‘&offset=’.$post_offset;
    $page_links = ‘<div class="dpsc_grid_pagination">‘ . $page_links . ‘</div>‘;
    }
    else {
    $per_page = $total;
    $offset =  »;
    $page_links =  »;
    }
    if ($order != ‘rand’) {
    $order_string = ‘orderby=post_date&order=’ . $order . ‘&’;
    }
    else {
    $order_string = ‘orderby=rand&’;
    }
    $products = get_posts($order_string . ‘numberposts=’ . $per_page . ‘&post_type=’ . $type . ‘&meta_key=price&category=’ . $category . $offset);
    if (is_array($products) && count($products) > 0) {
    $content .= ‘<div class="dpsc_grid_display">‘;
    $count = 1;
    $all_count = 0;
    foreach ($products as $product) {
    $output = dpsc_get_product_details($product->ID);
    if ($output) {
    $attachment_images =&get_children(‘post_type=attachment&post_status=inherit&post_mime_type=image&post_parent=’ . $product->ID);
    $main_image =  »;
    foreach ($attachment_images as $image) {
    $main_image = $image->guid;
    break;
    }
    $prod_permalink = get_permalink($product->ID);
    $content .= ‘<div class="dpsc_grid_product">‘;
    $content .= ‘<div class="dpsc_grid_product_image">‘;
    if ($main_image !=  ») {
    $content .= ‘<a href="' . $prod_permalink . '">post_title . ‘ »><img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['g_w'] . '&h=' . $dp_shopping_cart_settings['g_h'] . '&zc=1" alt="thumbnail" /></a>‘;
    }
    $content .= ‘</div>‘;
    $content .= ‘<div class="dpsc_grid_product_detail">‘;
    $content .= ‘<p class="title"><a href="' . $prod_permalink . '">post_title . ‘ »>’ . __($product->post_title) . ‘</a></p>‘;


    //importation champ personnalisé

    $content .= get_post_meta($post->ID, « altitude », true);





    $content .= ‘<form action="?page_id=572" method="post" enctype="multipart/form-data" name="form"></form>‘;
    $content .= ‘<p class="price">‘ . $output[‘price’] . ‘</p>‘;
    $content .= $output[‘start’];
    $content .= $output[‘add_to_cart’];
    $content .= $output[‘altitude’];
    $content .= $output[‘end’];
    $content .= ‘</div>‘;
    $content .= ‘</div>‘;
    if ($count === intval($column)) {
    $content .= ‘<div class="clear"></div>‘;
    $count = 0;
    }
    $count++;
    $all_count++;
    }
    }
    $content .= ‘<div class="clear"></div>‘ . $page_links . ‘<div class="clear"></div>‘;
    $content .= ‘</div>‘;
    $content .= ‘<div class="clear"></div>‘;
    }
    return $content;
    }

    /**
    * Add Meta Box for ease
    *
    */
    add_action(‘submitpost_box’, ‘dp_add_meta_box’);
    add_action(‘submitpage_box’, ‘dp_add_meta_box’);

    function dp_add_meta_box() {
    add_meta_box(‘dp_gui_box’, ‘DukaPress Product options’, ‘dp_rm_content_visibility_meta_box’, ‘post’, ‘side’, ‘high’);
    add_meta_box(‘dp_gui_box’, ‘DukaPress Product options’, ‘dp_rm_content_visibility_meta_box’, ‘page’, ‘side’, ‘high’);
    add_meta_box(‘dp_gui_box’, ‘DukaPress Product options’, ‘dp_rm_content_visibility_meta_box’, ‘duka’, ‘side’, ‘high’);
    }

    function dp_rm_content_visibility_meta_box() {
    $post_id = $_GET[‘post’];
    $content_price = get_post_meta($post_id, ‘price’, true);
    $new_price = get_post_meta($post_id, ‘new_price’, true);
    $content_stock = get_post_meta($post_id, ‘currently_in_stock’, true);
    $content_weight = get_post_meta($post_id, ‘item_weight’, true);
    $content_file = get_post_meta($post_id, ‘digital_file’, true);
    ?>
    <table>
    <tr><td><label for="price"><b></b></label></td><td><input id="price" type="text" name="price" value=" » /></td></tr>
    <tr><td><label for="new_price"><b></b></label></td><td><input id="new_price" type="text" name="new_price" value=" » /></td></tr>
    <tr><td><label for="currently_in_stock"><b></b></label></td><td><input id="currently_in_stock" type="text" name="currently_in_stock" value=" » /></td></tr>
    <tr><td><label for="item_weight"><b></b></label></td><td><input id="item_weight" type="text" name="item_weight" value=" » /> (in grams)</td></tr>
    <tr><td><label for="digital_file"><b></b></label></td><td><input id="digital_file" type="text" name="digital_file" value=" » /></td></tr>
    </table>

    <b></b>
    <div id="result">

    </div>

    <div id="mainField" style="clear:both">
    <p>
    <label for="optionname"></label>

    </p>
    <p>
    <label for="vname1"></label>

    </p>
    <p>
    <label for="vprice1"></label>

    </p>
    <div id="dp_var_fields"></div>
    </div>
    <p>



    </p>

    <?php
    }

    /**
    * This function displays the varitions.
    *
    */
    function dp_get_dropdown_option_to_display($post_id) {
    $content_opname = get_post_meta($post_id, 'dropdown_option', true);
    $show_state_result = '';

    if ($content_opname) {

    $optionnames = explode("||", $content_opname);

    foreach ($optionnames as $optionname) {
    $j++;
    $optionname1 = explode("|", $optionname);
    $show_state_result.=' <div style="border:1px solid;clear:both;width:250px">‘;
    $show_state_result.= ‘<p><b>‘ . ($optionname1[0]) . ‘</b></p>‘;
    for ($i = 1; $optionname1[$i]; $i++) {
    $show_state_result.=’<div style="float:left;width:200px;clear:both">‘;
    $optionname2 = explode(« ; », $optionname1[$i]);
    foreach ($optionname2 as $value) {
    $show_state_result.= ‘<div style="width:90px;float:left">‘ . $value . ‘</div>‘;
    }
    $show_state_result.=’</div>‘;
    }

    $show_state_result.=’
    <div id="dp_deletestring"><a href="#" id="' . $j . '">Delete</a>

    </div>
    <div style="clear:both"></div></div>‘;
    }
    }
    return $show_state_result;
    }

    /**
    * This function saves the meta box details.
    *
    */
    add_action(‘save_post’, ‘dp_save_meta_box’);

    function dp_save_meta_box($post_id) {
    // verify if this is an auto save routine.
    $content_counter = 1;
    //$content_opname= »;
    $varition_type =  »;

    if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE)
    return $post_id;

    // Check permissions
    if (‘page’ == $_POST[‘post_type’]) {
    if (!current_user_can(‘edit_page’, $post_id))
    return $post_id;
    }else {
    if (!current_user_can(‘edit_post’, $post_id))
    return $post_id;
    }

    // for price
    if (NULL == $_POST[‘price’]) {
    //do nothing
    } else {
    $content_price = $_POST[‘price’];

    update_post_meta($post_id, ‘price’, $content_price);
    }

    // for new price
    if (NULL == $_POST[‘new_price’]) {
    //do nothing
    } else {
    $content_price = $_POST[‘new_price’];

    update_post_meta($post_id, ‘new_price’, $content_price);
    }

    // for stocks
    if (NULL == $_POST[‘currently_in_stock’]) {
    //do nothing
    } else {
    $content_stock = $_POST[‘currently_in_stock’];
    update_post_meta($post_id, ‘currently_in_stock’, $content_stock);
    }

    // for weights
    if (NULL == $_POST[‘item_weight’]) {
    //do nothing
    } else {
    $content_weight = $_POST[‘item_weight’];
    update_post_meta($post_id, ‘item_weight’, $content_weight);
    }

    //for file
    if (NULL == $_POST[‘digital_file’]) {
    //do nothing
    } else {
    $content_file = $_POST[‘digital_file’];
    update_post_meta($post_id, ‘digital_file’, $content_file);
    }

    // for option name
    if (NULL == $_POST[‘varitaionnumber’]) {
    //do nothing
    } else {
    $content_counter = $_POST[‘varitaionnumber’];
    update_post_meta($post_id, ‘_Content_Counter’, $content_counter);
    }
    }

    /**
    * This function saves variations.
    *
    */
    add_action(‘wp_ajax_save_variationdata’, ‘dp_rm_varition_save_data’);

    function dp_rm_varition_save_data() {

    if ($_POST && $_POST[‘action’] == « save_variationdata ») {
    $counter = $_POST[‘counter’];
    $postid = $_POST[‘postid’];
    $prev_option = get_post_meta($postid, ‘dropdown_option’, true);

    // making || in each option name

    if ($prev_option) {
    $prev_option_new = $prev_option;
    $varition_type .= $prev_option_new . ‘||’;
    }

    // check for the validation that, option name should not be null
    if($_POST[‘optionname’])
    {
    $varition_type.=$_POST[‘optionname’] . ‘|’;
    for ($i = 1; $i
    <div style="clear:both;width:250px">
    <!--for showing the data -->

    </div>
    array(
    ‘name’ => __( ‘Products’, »dp-lang » ),
    ‘singular_name’ => __( ‘Product’, »dp-lang » ),
    ‘add_new’ => __( ‘Add New Product’, »dp-lang » ),
    ‘add_new_item’ => __( ‘Add New Product’, »dp-lang » ),
    ‘edit’ => __( ‘Edit’ , »dp-lang »),
    ‘edit_item’ => __( ‘Edit Product’, »dp-lang » ),
    ‘new_item’ => __( ‘New Product’ , »dp-lang »),
    ‘view’ => __( ‘View Product’, »dp-lang » ),
    ‘view_item’ => __( ‘View Product’ , »dp-lang »),
    ‘search_items’ => __( ‘Search Products’ , »dp-lang »),
    ‘not_found’ => __( ‘No products found’ , »dp-lang »),
    ‘not_found_in_trash’ => __( ‘No products found in Trash’, »dp-lang » )
    ),
    ‘description’ => __(‘Products for use with DukaPress’, »dp-lang »),
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘capability_type’ => ‘post’,
    ‘taxonomies’ => array( ‘category’, ‘post_tag’),
    ‘menu_position’ => 30,
    ‘publicly_queryable’ => true,
    ‘exclude_from_search’ => false,
    ‘query_var’ => true,
    ‘hierarchical’ => false,
    ‘menu_icon’ => DP_PLUGIN_URL . ‘/images/dp_icon.png’,
    ‘rewrite’ => array(‘slug’ => ‘products’, ‘with_front’ => false),
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’, ‘custom-fields’, ‘posts’, ‘revisions’, ‘trackbacks’ )
    ));
    }


    add_shortcode(‘dp_search’, ‘dp_custom_search_fn’);
    function dp_custom_search_fn($atts, $content = null) {
    $dp_shopping_cart_settings = get_option(‘dp_shopping_cart_settings’);
    extract(shortcode_atts( array(
    ‘per_page’ =>  »,
    ‘column’ => ‘3’
    ), $atts));
    global $dp_custom_search_word;
    $dp_custom_search_word = trim(esc_attr($_GET[‘dp_s’]));
    if ($dp_custom_search_word !=  ») {
    $custom_search_args = array(‘post_type’ => ‘duka’, ‘meta_key’ => ‘price’);
    if (!empty($per_page)) {
    $pagenum = isset($_GET[‘dpage’]) ? $_GET[‘dpage’] : 1;
    add_filter( ‘posts_where’, ‘dp_product_search_filter’);
    $count = count(query_posts($custom_search_args));
    wp_reset_query();
    $page_links = paginate_links( array(
    ‘base’ => add_query_arg( ‘dpage’, ‘%#%’ ),
    ‘format’ =>  »,
    ‘prev_text’ => __(‘«’),
    ‘next_text’ => __(‘»’),
    ‘total’ => ceil($count / $per_page),
    ‘current’ => $pagenum
    ));
    $page_links = ‘<div class="dpsc_grid_pagination">‘ . $page_links . ‘</div>‘;
    $custom_search_args[‘posts_per_page’] = intval($per_page);
    $custom_search_args[‘paged’] = intval($pagenum);
    }
    else {
    $per_page = $total;
    $page_links =  »;
    }

    add_filter( ‘posts_where’, ‘dp_product_search_filter’);
    $products = query_posts($custom_search_args);
    global $wp_query;
    wp_reset_query();
    if (is_array($products) && count($products) > 0) {
    $content .= ‘<div class="dpsc_grid_display">‘;
    $count = 1;
    $all_count = 0;
    foreach ($products as $product) {
    $output = dpsc_get_product_details($product->ID);
    if ($output) {
    $attachment_images =&get_children(‘post_type=attachment&post_status=inherit&post_mime_type=image&post_parent=’ . $product->ID);
    $main_image =  »;
    foreach ($attachment_images as $image) {
    $main_image = $image->guid;
    break;
    }
    $prod_permalink = get_permalink($product->ID);
    $content .= ‘<div class="dpsc_grid_product">‘;
    $content .= ‘<div class="dpsc_grid_product_image">‘;
    if ($main_image !=  ») {
    $content .= ‘<a href="' . $prod_permalink . '">post_title . ‘ »><img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['g_w'] . '&h=' . $dp_shopping_cart_settings['g_h'] . '&zc=1" alt="thumbnail" /></a>‘;
    }
    $content .= ‘</div>‘;
    $content .= ‘<div class="dpsc_grid_product_detail">‘;
    $content .= ‘<p class="title"><a href="' . $prod_permalink . '">post_title . ‘ »>’ . __($product->post_title) . ‘</a></p>‘;
    $content .= ‘<p class="detail">‘ . $product->post_excerpt . ‘</p>‘;
    $content .= ‘<p class="price">‘ . $output[‘price’] . ‘</p>‘;
    $content .= $output[‘start’];
    $content .= $output[‘add_to_cart’];
    $content .= $output[‘end’];
    $content .= ‘</div>‘;
    $content .= ‘</div>‘;
    if ($count === intval($column)) {
    $content .= ‘<div class="clear"></div>‘;
    $count = 0;
    }
    $count++;
    $all_count++;
    }
    }
    $content .= ‘<div class="clear"></div>‘ . $page_links . ‘<div class="clear"></div>‘;
    $content .= ‘</div>‘;
    $content .= ‘<div class="clear"></div>‘;
    }
    else {
    $content .= ‘No Results Found.’;
    }
    }
    else {
    $content .= ‘No Results Found.’;
    }
    return $content;
    }

    function dp_product_search_filter($where) {
    global $wpdb, $dp_custom_search_word;
    $dp_search_query_likes = explode(‘ ‘, $dp_custom_search_word);
    if (is_array($dp_search_query_likes)) {
    $final_like = array();
    foreach($dp_search_query_likes as $dp_search_query_like) {
    $final_like[] = « LIKE ‘%{$dp_search_query_like}%' »;
    }
    $final_like = implode( » AND {$wpdb->posts}.post_title « , $final_like);
    $where .=  » AND {$wpdb->posts}.post_title {$final_like} »;
    }
    return $where;
    }

    ?>

    A noter que j’ai mis l’appel du champ personnalisé juste après le commentaire « //importation champ personnalisé ». Mes produits dépendent du template qui appelle les articles (single.php).

    Je ne sais si toutes ces informations suffiront à résoudre le problème

    Merci encore

    #772927
    Guy
    Participant
    Maître WordPress
    14817 contributions

    et en mettant $product_id à la place de $post->ID ?

    #772928
    Cedric C.
    Participant
    Maître WordPress
    612 contributions

    Nan il ne veut rien savoir. Pas d’erreur mais il n’affiche pas le critère voulu

    #772929
    Guy
    Participant
    Maître WordPress
    14817 contributions

    excuse moi, je me suis mélangé les pinceaux, dans cette fonction tu peux mettre $product->ID

    #772930
    Cedric C.
    Participant
    Maître WordPress
    612 contributions

    T’es le meilleur ça fonctionne ✅

    Merci

    Reste encore ceci à résoudre et c’est tout bon, mon catalogue personnalisé va fonctionner

7 sujets de 1 à 7 (sur un total de 7)
  • Vous devez être connecté pour répondre à ce sujet.