• Good Morning,

    I upgraded to woocommerce 3.0.5 and using wordpress version 4.7.4. In the Woocommerce Sample Plugin, I am using custom price and free shipping. However, when I add the product to the cart, it is using the full price. I have tried to debug the code in woocommerce-sample.php and can not follow where it is suppose to update the cart price with the custom price. Any help will be greatly appreciated, because I am unable to launch my clients site.

    Thanks so much.

Viewing 9 replies - 1 through 9 (of 9 total)
  • OK fine… Someone posted some code in the other topic which is now closed (fantastic idea, how to get now an idea to debug that !). May we continue on github (here : https://github.com/isikom/woocommerce-sample) to get some help ?

    I had the same problem. However, I found this that another user posted and it worked like charm! Just add to your functions.php file.

    add_action( 'woocommerce_before_calculate_totals','cp_add_custom_price', 10, 1);
    function cp_add_custom_price( $cart_obj ) {
    // This is necessary for WC 3.0+
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    return;

    foreach ( $cart_obj->get_cart() as $key => $value ) {
    if($value['sample']){
    $product_id = $value['product_id'];
    $sample_price_mode = get_post_meta($product_id, 'sample_price_mode', true) ? get_post_meta($product_id, 'sample_price_mode', true) : 'default';
    $sample_price = get_post_meta($product_id, 'sample_price', true) ? get_post_meta($product_id, 'sample_price', true) : 0;
    if ($sample_price_mode === 'custom'){
    $price = $sample_price;
    }else if ($sample_price_mode === 'free'){
    $price = 0;
    }else{
    $price = $value['data']->price;
    }
    $value['data']->set_price( $price );
    }

    }
    }

    @jade1996, I tried this code at the beginning of my functions fils, lead me to a global 500 error on whole website, including admin ??

    @delacourcorp the code worked for me, maybe you did not copied it all. The problem is, when in #quick_view i get an empty page – only “0” is displayed in <body>.
    If i click back in browser, the sample is in the cart.. still, I’d prefer for it to work as in product page.
    @jade1996 can u confirm or have a solution? ^_^

    @delacourcorp I placed the code at the end of my functions.php file. Have you tried that?

    @jade1996, thanks for that info, I’ll try it like that ??

    @jade1996, thank you code works fine! Oh what a relief!!!

    @delacour.corp, if you have a child theme just add this code to functions.php in the child folder or through the admin. If it doesn’t work just remove the code through FTP.

    Great job guys.

    Hey! Got the code above working just fine for me but it still displays the listing price instead of the custom price in the ‘minicart’. I figure this would be fixed in the same vain, has anyone else ran into this yet?

    Thread Starter btsllc

    (@btsllc)

    Yes, I figured it out. In order to fix this issue, I had to modify the mini-cart.php template.

    1) Please create a child theme and add the following directory [woocommerce—>cart].
    2)Copy the parent theme mini-cart.php to your child theme cart directory.
    3) I modified the following code (this code may be different based on your parent theme)

    <li class=”clearfix”>
    <span class=”quantity”><?php printf( ‘%s × %s’, $cart_item[‘quantity’], ”); ?></span>
    “>
    <?php echo apply_filters(‘woocommerce_widget_cart_product_title’, $_product->get_title(), $_product ); ?>

    <!– update the custom price passed to the mini cart from plugin Woocommerce Sample–>
    <!–begining code–>
    <?php if($cart_item[‘sample’]){ ?>
    <span style=’position: relative; right: -42px !important;’ class=’price’><?php echo $product_price; ?></span>
    <?php }else{ ?>
    <span class=’price’><?php echo $product_price; ?></span>
    <?php } ?>
    <!–end code–>

    Hope this helps!!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sample is adding full price when using custom option’ is closed to new replies.