Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Laneige90

    (@laneige90)

    Hi there,

    Sorry it was a mistake on our side due to the server visibility.

    Amazing support response time by the way!

    Thanks for you help.

    George

    Thread Starter Laneige90

    (@laneige90)

    Excellent, Thank you!

    George

    Thread Starter Laneige90

    (@laneige90)

    Any thoughts on this?

    Thread Starter Laneige90

    (@laneige90)

    Hi Dan

    This is the php error I’m getting

    [28-Apr-2017 18:44:30 UTC] PHP Fatal error: Function name must be a string in /var/sites/d/drum-attic.co.uk/public_html/wp-content/plugins/weight-based-shipping-for-woocommerce/server/src/Services/LegacyConfigService/LegacyConfigRulesStorage.php on line 34

    Thread Starter Laneige90

    (@laneige90)

    Hi, sorry about the late reply here!

    Thank you Kharis, I had a look at that function, however there has been a development. The bespoke products DO add to cart if a normal dashboard created one is added first! To me, this points to some kind of cart config that must be applied when normal products are added which I’m missing from my function.

    Still looking into it.

    Thread Starter Laneige90

    (@laneige90)

    Hi there

    Ah I did think that at first, but I forgot to mention that the products are added into the database as normal once this code has been executed. They show up in the woocommerce dashboard area, but they are not added into the cart at this time.

    Thread Starter Laneige90

    (@laneige90)

    Hi, thanks for your response.

    No, I am not using that conditional tag within the function.

    Here is my create product and add to cart function here…

    function createnewfoamproduct() {
        global $woocommerce;
    
        // import some data from the front end
        $dimensions = $_POST['dimensions'];
        $measurmentunit = $_POST['unit'];
        $thumbnailid = $_POST['shapeimgid'];
        $shapeid = $_POST['shapeid'];
    
        $new_post = array(
            'post_title' => 'Foam: ' . $_POST['foamtype'] . ' Size: ' . $dimensions[0] . $measurmentunit . ' x ' . $dimensions[1]
            . $measurmentunit . ' x ' . $dimensions[2] . $measurmentunit,
           //'post_status' => 'private',
            'post_type' => 'product'
        );
    
        $post_id = wp_insert_post($new_post);
    
        // Change post name for include unique identifier
        $currenttitle = get_the_title($post_id);
    
        $cutcode = $post_id - 1300;
    
        $my_post = array(
            'ID' => $post_id,
            'post_status' => 'publish',
            'post_author' => '1',
            'post_title' => $currenttitle . " - Ref: " . $cutcode,
        );
    
        wp_update_post($my_post);
    
        $shipping_terms = get_term_by( 'slug', $_POST['shipping'], 'product_shipping_class' );
    
        wp_set_post_terms($post_id, array( $shipping_terms->term_id ), 'product_shipping_class' );
    
        update_post_meta($post_id, '_foamtype', $_POST['foamtype']);
        update_post_meta($post_id, '_price', $_POST['foamprice']);
        update_post_meta($post_id, '_visibility', 'visible');
        update_post_meta($post_id, '_stock_status', 'instock');
        update_post_meta($post_id, '_tax_status', 'taxable');
        update_post_meta($post_id, '_regular_price', $_POST['foamprice']);
        update_post_meta($post_id, '_featured', 'no');
        update_post_meta($post_id, '_length', $dimensions[0]);
        update_post_meta($post_id, '_width', $dimensions[1]);
        update_post_meta($post_id, '_height', $dimensions[2]);
        for ($i = 0; $i < count($dimensions); $i++) {
            add_post_meta($post_id, '_extraDimensions', $dimensions[$i]);
        }
        update_post_meta($post_id, '_polywrap', $_POST['polywrapid']);
        update_post_meta($post_id, '_topper', $_POST['topperid']);
        update_post_meta($post_id, '_holes', $_POST['holesid']);
        update_post_meta($post_id, '_stockinette', $_POST['stockinetteid']);
        update_post_meta($post_id, '_thumbnail_id', $thumbnailid);
        update_post_meta($post_id, '_backorders', 'no');
        update_post_meta($post_id, '_shapeid', $shapeid);
        update_post_meta($post_id, '_unit', $_POST['unit']);
        update_post_meta($post_id, '_foam', $_POST['foam']);
        update_post_meta($post_id, '_shapequantity', $_POST['quantity']);
    
        $woocommerce->cart->add_to_cart($post_id, $_POST['quantity']);  
    
        echo $post_id;
    
        wp_die();
    }
Viewing 7 replies - 1 through 7 (of 7 total)