Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lalatabest

    (@lalatabest)

    I see emptiness on the page. and this is the code that I’m using:

    add_action( ‘woocommerce_single_product_summary’, function() {
    if ( ! class_exists( ‘WCAPRI_Product’ ) ) {
    return;
    }

    global $product;
    $wcapri_product = new WCAPRI_Product( $product->get_id(), $product );
    $bulk_rules = array();
    foreach ( $wcapri_product->get_single_advanced_prices() as $k => $v ) {
    if ( $v[‘type’] == ‘bulk’ ) {
    $new_rules = isset( $v[‘bulk_rules’] ) ? $v[‘bulk_rules’] : ( isset( $v[‘condition’] ) ? array( $v ) : $v );
    $bulk_rules = array_merge( $bulk_rules, $new_rules );
    }
    }
    // Get global pricing
    foreach( wcapri_get_advanced_pricings() as $k => $v ) {
    $type = get_post_meta( $v->ID, ‘_action_type’, true );
    $conditions = get_post_meta( $v->ID, ‘_pricing_conditions’, true );
    $rules = get_post_meta( $v->ID, ‘_advanced_pricing’, true );
    if ( $type == ‘bulk’ && true == wpc_match_conditions( $conditions, array( ‘context’ => ‘wcapri’, ‘product’ => $product->get_id() ) ) ) {
    $bulk_rules = array_merge( $bulk_rules, $rules );
    }
    }
    // Sort
    usort( $bulk_rules, function( $a, $b ) {
    if ($a[‘condition’][‘min’] == $b[‘condition’][‘min’]) return 0;
    return $a[‘condition’][‘min’] < $b[‘condition’][‘min’] ? -1 : 1;
    });
    // Filter empty
    foreach ( $bulk_rules as $k => $v ) {
    if ( empty( $v[‘action’][‘amount’] ) ) {
    unset( $bulk_rules[ $k ] );
    }
    }
    if ( ! is_array( $bulk_rules ) ) {
    return;
    }
    // Show table
    ?>
    <style>
    .wcapri-pricing-table {
    margin-bottom: 10px;
    }
    .wcapri-pricing-table tr {
    }
    .wcapri-pricing-table td {
    border: 1px solid #ccc;
    text-align: center;
    padding: 5px;
    font-size: 80%;
    }
    </style>
    <table class=”wcapri-pricing-table wcapri-bulk-pricing-table” cellpadding=”20″>
    <tr><?php
    foreach ( $bulk_rules as $k => $v ) :
    $min = absint( $v[‘condition’][‘min’] );
    $max = absint( $v[‘condition’][‘max’] );
    ?><td><?php echo ( $min == $max ) ? $min : $min . ‘ – ‘ . $max; ?></td><?php
    endforeach;
    ?></tr>

    <tr><?php
    foreach ( $bulk_rules as $k => $v ) :
    if ( $product->is_type( ‘variable’ ) ) :
    $prices = $product->get_variation_prices( true );
    $min_price = current( $prices[‘price’] );
    $min_price = wcapri_apply_price_action( $min_price, $v[‘action’][‘amount’] );
    $max_price = end( $prices[‘price’] );
    $max_price = wcapri_apply_price_action( $max_price, $v[‘action’][‘amount’] );
    if ( $min_price !== $max_price ) {
    $price = wc_format_price_range( $min_price, $max_price ) . $product->get_price_suffix();
    } else {
    $price = wc_price( $min_price ) . $product->get_price_suffix();
    }
    ?><td><?php echo $price; ?></td><?php
    else :
    $price = wcapri_apply_price_action( $product->get_price(), $v[‘action’][‘amount’] );
    ?><td><?php echo wc_price( $price ); ?></td><?php
    endif;
    endforeach;
    ?></tr><?php
    ?></table><?php
    }, 15 );

    Thread Starter lalatabest

    (@lalatabest)

    The php code is to display a price table on the product page of the store. I created the template of the product page with Divi builder, so I have put the snippet shortcode with the code module of this builder. But it does not do anything.

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