• Resolved dxmdigital

    (@dxmdigital)


    My client runs courses and I have developed their website to sell them via woocommerce. I am trying to add some more types of stock statuses for their website such as coming soon and dates to be confirmed. I am looking for help with my existing code to achieve this. This issue I have is that when I have it set to dates to be confirmed (dtbc on the code) it turns the ability to purchase off but also removes the explanation test on the product page as well. What I am looking for is help with making it so that the status is there and the ability to purchase is off. Please see my code below:
    `// Add new stock status options
    function filter_woocommerce_product_stock_status_options( $status ) {
    // Add new statuses
    $status[‘coming_soon’] = __( ‘Coming soon’, ‘woocommerce’ );
    $status[‘dtbc’] = __( ‘Dates to be confirmed’, ‘woocommerce’ );

    return $status;
    }
    add_filter( ‘woocommerce_product_stock_status_options’, ‘filter_woocommerce_product_stock_status_options’, 10, 1 );

    // Availability text
    function filter_woocommerce_get_availability_text( $availability, $product ) {
    switch( $product->stock_status ) {
    case ‘coming_soon’:
    $availability = __( ‘Coming soon’, ‘woocommerce’ );
    break;
    case ‘dtbc’:
    $availability = __( ‘Dates to be confirmed’, ‘woocommerce’ );
    break;
    }
    return $availability;
    }
    add_filter( ‘woocommerce_get_availability_text’, ‘filter_woocommerce_get_availability_text’, 10, 2 );
    //Turn of the ability to purchase through filter
    add_filter(‘woocommerce_is_purchasable’, ‘dbtc_non_purchasble’, 10, 2);

    function dbtc_non_purchasble( $availability, $product ) {

    // this is a field added using ‘Advance Custom Fields’ plugin
    $availability = get_field(‘dbtc’, $product->stock_status);

    if($availability && $is_purchasable)
    return false;
    }

    Many thanks in advance for any help.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Customise stock status’ is closed to new replies.