Skip to content

Instantly share code, notes, and snippets.

@bologer
Last active September 1, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bologer/3b344c4d3c3972a08ce8bc2ff1f28006 to your computer and use it in GitHub Desktop.
Save bologer/3b344c4d3c3972a08ce8bc2ff1f28006 to your computer and use it in GitHub Desktop.
1 пункт, скрыть sidebar, цены
  1. Открыть wp-content/themes/royal/functions.php
  2. Добавить функцию
/**
 * Check whether user is a cardholder or not.
 * @return bool
 */
function is_cardholder()
{
    if (!is_user_logged_in()) {
        return false;
    }

    $user = wp_get_current_user();

    return in_array('cardholder', $user->roles, true);
}
  1. Открыть wp-content/themes/royal/woocommerce/content-single-product.php

Заменить:

<div class="product_side_bar" style="width:255px;">

На это:

<div class="product_side_bar" style="width:255px; <?= is_cardholder() ? 'display: none; opacity: 0; z-index: -9999' : '' ?>">

Заменить:

<div class="tabs tabs-default">
     <div class="col-md-9">

На:

<div class="tabs tabs-default">
    <div class="<?= is_cardholder() ? 'col-xs-12' : 'col-md-9' ?>">
  1. Открыть wp-content/plugins/woocommerce/templates/single-product/cart-top-small.php

Заменить:

<?php
    $sales_price = stips_get_sales_price($product);
    if ($product->is_on_sale()) {
        ?>
        <div class="stips-product-short-price-amount"><?php echo $sales_price ?> </div>
        <div class="footer-product-price-regular-single">
            <del><?php echo $current_price = stips_get_current_price($product); ?></del>
        </div>
        <?php
    } else {
        ?>
        <div class="stips-product-short-price-amount"><?php echo $current_price = stips_get_current_price($product); ?></div>

        <?php
    }
    ?>

На:

<?php
    if (!is_cardholder()):
        $sales_price = stips_get_sales_price($product);
        if ($product->is_on_sale()) {
            ?>
            <div class="stips-product-short-price-amount"><?php echo $sales_price ?> </div>
            <div class="footer-product-price-regular-single">
                <del><?php echo $current_price = stips_get_current_price($product); ?></del>
            </div>
            <?php
        } else {
            ?>
            <div class="stips-product-short-price-amount"><?php echo $current_price = stips_get_current_price($product); ?></div>

            <?php
        }
    endif;
    ?>

Заменить:

<p><a href="/?add-to-cart=<?php echo get_the_ID(); ?>&a=redirect"><?= __('Zaplatit hned', ETHEME_DOMAIN) ?></a>
        </p>

На:

<?php if (!is_cardholder()) : ?>
            <p>
                <a href="/?add-to-cart=<?php echo get_the_ID(); ?>&a=redirect"><?= __('Zaplatit hned', ETHEME_DOMAIN) ?></a>
            </p>
        <?php endif; ?>

Заменить:

<div class="stips-product-short-price-varients">
        <ul>
            <li>
                <?php $mapkey = get_post_meta($product->id, 'eg-slug');
                $maplocation = $mapkey[0];
                $locations = (explode(",", $maplocation));
                $belolocation = get_post_meta($product->id, 'eg-title');
                $loc2 = $belolocation[0];
                $loc = (explode("and", $loc2));
                foreach ($locations as $key => $val) {
                    $val2 = $loc[$key];

                    $siteurl = get_site_url();
                    $str = preg_replace('/\s+/', '', $val);

                    ?>
                    <a href="<?php echo $siteurl; ?>/<?php echo $str; ?>"><?php echo $val2; ?></a>
                    <br>
                    <?php


                }
                ?>

            </li>
        </ul>
    </div>

На:

<?php if (!is_cardholder()): ?>
        <div class="stips-product-short-price-varients">
            <ul>
                <li>
                    <?php $mapkey = get_post_meta($product->id, 'eg-slug');
                    $maplocation = $mapkey[0];
                    $locations = (explode(",", $maplocation));
                    $belolocation = get_post_meta($product->id, 'eg-title');
                    $loc2 = $belolocation[0];
                    $loc = (explode("and", $loc2));
                    foreach ($locations as $key => $val) {
                        $val2 = $loc[$key];

                        $siteurl = get_site_url();
                        $str = preg_replace('/\s+/', '', $val);

                        ?>
                        <a href="<?php echo $siteurl; ?>/<?php echo $str; ?>"><?php echo $val2; ?></a>
                        <br>
                        <?php


                    }
                    ?>

                </li>
            </ul>
        </div>
    <?php endif; ?>
  1. Открыть wp-content/themes/royal/woocommerce/content-product.php

Заменить:

<?php
                    /**
                     * If product is on sale
                     */
                    if ($product->is_on_sale()): ?>
                        <div class="footer-product-price-sale"><?= stips_get_sales_price($product) ?></div>
                        <!-- /.footer-product-price -->
                        <div class="footer-product-price-regular">
                            <del><?= stips_get_current_price($product) ?></del>
                        </div>

                        <!-- /.footer-product-price-regular -->
                    <?php else: ?>
                        <div class="footer-product-price-regular"><?= stips_get_current_price($product) ?></div>
                        <!-- /.footer-product-price-regular -->
                    <?php endif; ?>

На:

<?php
                    if (!is_cardholder()):
                        /**
                         * If product is on sale
                         */
                        if ($product->is_on_sale()): ?>
                            <div class="footer-product-price-sale"><?= stips_get_sales_price($product) ?></div>
                            <!-- /.footer-product-price -->
                            <div class="footer-product-price-regular">
                                <del><?= stips_get_current_price($product) ?></del>
                            </div>

                            <!-- /.footer-product-price-regular -->
                        <?php else: ?>
                            <div class="footer-product-price-regular"><?= stips_get_current_price($product) ?></div>
                            <!-- /.footer-product-price-regular -->
                        <?php endif; ?>
                    <?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment