Pb de maj des prix suite à variation devises (Créer un compte)

  • Statut : non résolu
11 sujets de 1 à 11 (sur un total de 11)
  • Auteur
    Messages
  • #547822
    athanar
    Participant
    Initié WordPress
    10 contributions

    Bonjour,

    Problème(s) rencontré(s) : J’essaie de mettre à jour des prix de produits suite à une modification de devises (bitcoins).

    Pour ce faire suite à la maj de la devise, je lance cette fonction :

    function usd_to_btc_products_update(){
    if ( ! function_exists( ‘woothemes_queue_update’ ) ) {
    require_once( ‘woo-includes/woo-functions.php’ );
    }
    global $woocommerce;
    $currrate = get_option( ‘usd_to_btc_rate’);
    echo(‘Taux de conversion : ‘.$currrate.’,id : ‘.the_ID());
    $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1);
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $product = get_product(the_ID());
    if($product->product_type == “variable”){
    echo(‘variable’);
    $variations = $product->get_available_variations();
    foreach ($variations as $variation){
    $variation_id = $variation;
    $variable_product= new WC_Product_Variation( $variation_id );
    $regprice = $variable_product->regular_price;
    $regpriceusd = get_post_meta( $variation_id, ‘_variable_regular_price_usd’, true );
    $salepriceusd = get_post_meta( $variation_id, ‘_variable_sale_price_usd’, true );
    $saleprice = $variable_product->sale_price;
    if($regpriceusd){
    update_post_meta($variation_id, ‘_regular_price’, number_format($regpriceusd*$currrate,8,’.’,”));
    update_post_meta($variation_id, ‘_price’, number_format($regpriceusd*$currrate,8,’.’,”));
    }
    if($salepriceusd){
    update_post_meta($variation_id, ‘_sale_price’, number_format($salepriceusd*$currrate,8,’.’,”));
    update_post_meta($variation_id, ‘_price’, number_format($salepriceusd*$currrate,8,’.’,”));
    }
    }
    $variable_productobj= new WC_Product_Variable( $product );
    $variable_productobj->variable_product_sync($product->id);

    }
    else{
    $product_id = gettheID();
    echo(‘
    Modification produit : ‘.gettheID());

    $regprice = get_post_meta( gettheID(), ‘_regular_price_usd’, true );
    $saleprice = get_post_meta( ID(), ‘_sale_price_usd’, true );
    echo(‘. Before : regprice(‘.$regprice.’),saleprice(‘.$saleprice.’)’);
    if($regprice){
    update_post_meta(ID(), ‘_regular_price’, number_format($regprice*$currrate,8,’.’,”));
    update_post_meta(ID(), ‘_price’, number_format($regprice*$currrate,8,’.’,”));
    }
    if($saleprice){
    update_post_meta(ID(), ‘_sale_price’, number_format($saleprice*$currrate,8,’.’,”));
    update_post_meta(ID(), ‘_price’, number_format($saleprice*$currrate,8,’.’,”));
    }
    echo(‘. After : regprice(‘.$regprice.’),saleprice(‘.$saleprice.’)’);
    }
    endwhile;
    wp_reset_query();

    le currate est ok, l’id aussi. Le product me renvoie un Array.
    Mais les champs $product->product_type, _regular_price, _price sont vides.

    Est ce qu’il me manque quelque chose?
    Est ce qu’il y’a un moyen de lister la liste des champs disponibles avec leur valeur pour les “product”?

    Merci d’avance pour votre aide.
    Athanar

    #997319
    didier07
    Participant
    Maître WordPress
    1965 contributions
    athanar wrote:
    Le product me renvoie un Array.

    Où dans ton code ?

    Sinon, var_dump( $product) sera très bavard 😉

    #997320
    athanar
    Participant
    Initié WordPress
    10 contributions

    Un grand merci pour ta réponse.

    Pour te répondre : pas dans ce code, j’ai retiré le echo(”.$product).

    Je teste le var_dump, thanks.

    Athanar

    #997321
    athanar
    Participant
    Initié WordPress
    10 contributions

    ah j’ai un bool(false) ca veut dire qu’il trouve rien?

    Pourtant la sortie des echo me sort bien l’id :
    Taux de conversion : 0.00368555,id : 51301bool(false) 5130151301
    Modification produit : 5130151301. Before : regprice(),saleprice(). After : regprice(),saleprice()51280bool(false) 5128051280

    #997322
    didier07
    Participant
    Maître WordPress
    1965 contributions

    Tu as essayé var_dump( $product = get_product( get_the_ID()) );

    #997323
    athanar
    Participant
    Initié WordPress
    10 contributions

    J’ai limité la requete pour limiter à deux résultats. Voici ce que j’obtiens :

    Taux de conversion : 0.0037184451301id product : 51301object(WC_Product_Simple)#850 (6) { [“id”]=> int(51301) [“post”]=> object(WP_Post)#851 (24) { [“ID”]=> int(51301) [“post_author”]=> string(2) “50” [“post_date”]=> string(19) “2015-02-16 09:55:26” [“post_date_gmt”]=> string(19) “2015-02-16 09:55:26” [“post_content”]=> string(2060) “Description: Feature: Wall charger: Weight:17g Input 100-240V 50/60Hz 0.15A Output:5V m 1A Convenient to use for home, office and travel. Easy to use: just plug the adapter in a wall outlet and connect to your iPod and iPhone for recharging. Data Cable: Wight:22g Compact design and light weight High speed data transfer Connect the computer’s USB port to your iPhone to sync and charge your iPhone simultaneously Color:red,yellow,green,white,black,purple,hot pink,pink,blue Compatible with :ipod2 iPhone 4 3G 3GS 4G 4S Package Includes : 1 x EU Wall charger 1 x Data Cable Note:Accessory Only! Cellphone not included.

    Merci pour votre aide.
    Athanar

    #997324
    athanar
    Participant
    Initié WordPress
    10 contributions

    arf on peut pas éditer sa réponse 🙂
    VOici la suite :

    [“post_title”]=> string(71) “Wall Charger EU Plug Adapter+USB Data Sync Cable For iPod iPhone (Copy)” [“post_excerpt”]=> string(712) “✓ Pay with Bitcoins
    ✓ International Shipping
    ✓ 3 working days dispatch
    ✓ Free shipping
    ✓ Free tracking number on items over $40
    ✓ Safe online transaction
    ✓ 100% Confidential
    ✓ Tested & approved” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(6) “closed” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(68) “wall-charger-eu-plug-adapterusb-data-sync-cable-for-ipod-iphone-copy” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2015-03-03 10:35:06” [“post_modified_gmt”]=> string(19) “2015-03-03 10:35:06” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(98) “https://pesobang.com/product/wall-charger-eu-plug-adapterusb-data-sync-cable-for-ipod-iphone-copy/” [“menu_order”]=> int(0) [“post_type”]=> string(7) “product” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“filter”]=> string(3) “raw” } [“product_type”]=> string(6) “simple” [“dimensions”:protected]=> string(0) “” [“shipping_class”:protected]=> string(0) “” [“shipping_class_id”:protected]=> int(0) } 5130151301
    Modification produit : 5130151301. Before : regprice(),saleprice(). After : regprice(),saleprice()51280id product : 51280object(WC_Product_Variable)#903 (8) { [“children”]=> NULL [“total_stock”]=> NULL [“id”]=> int(51280) [“post”]=> object(WP_Post)#851 (24) { [“ID”]=> int(51280) [“post_author”]=> string(1) “1” [“post_date”]=> string(19) “2015-02-13 16:02:05” [“post_date_gmt”]=> string(19) “2015-02-13 16:02:05” [“post_content”]=> string(8491) “Descriptions:
    Water Proof:Fully submersible to 6.6’ / 2 m for 30 minutes
    Dirt Proof:Sealed from dirt & dust particles – meets or exceeds IP-68 Ingress Protection Rating
    Snow Proof:Sealed from snow & ice – meets or exceeds IP-68 Ingress Protection Rating

    [“post_title”]=> string(66) “PC Waterproof Shockproof DirtProof Snow Proof Case For iPhone 4 4S” [“post_excerpt”]=> string(712) “✓ Pay with Bitcoins
    ✓ International Shipping
    ✓ 3 working days dispatch
    ✓ Free shipping
    ✓ Free tracking number on items over $40
    ✓ Safe online transaction
    ✓ 100% Confidential
    ✓ Tested & approved” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(6) “closed” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(66) “pc-waterproof-shockproof-dirtproof-snow-proof-case-for-iphone-4-4s” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2015-03-03 10:34:05” [“post_modified_gmt”]=> string(19) “2015-03-03 10:34:05” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(52) “https://pesobang.com/?post_type=product&p=51280” [“menu_order”]=> int(0) [“post_type”]=> string(7) “product” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“filter”]=> string(3) “raw” } [“product_type”]=> string(8) “variable” [“dimensions”:protected]=> string(0) “” [“shipping_class”:protected]=> string(0) “” [“shipping_class_id”:protected]=> int(0) } variableProduct prices updated successfully.

    #997325
    athanar
    Participant
    Initié WordPress
    10 contributions

    J’ai l’impression que ca me remonter pas toutes les infos 😕

    #997326
    didier07
    Participant
    Maître WordPress
    1965 contributions

    Il te remonte un objet WP_Post et pas WP_Product :fire:
    Il faut que tu récupère le produit autrement 🙂

    #997327
    athanar
    Participant
    Initié WordPress
    10 contributions

    Ok noté, je me suis servit des classes WP_Product et WC_Product_Variable

    Merci beaucoup Didier.
    Bonne soirée.

    #997328
    didier07
    Participant
    Maître WordPress
    1965 contributions

    Bonne soirée 😉

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