Woocomemrce add text after price plugin and php code

<?php 

add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );

function njengah_text_after_price($price){

    $text_to_add_after_price  = ' / por unidad'; //change text in bracket to your preferred text

    return $price .   $text_to_add_after_price;

}


add_action('woocommerce_add_to_cart', 'custome_add_to_cart');

Woocomemerce edit quantity when add to cart plugin and php code

<?php



add_action('woocommerce_add_to_cart', 'custome_add_to_cart');

function custome_add_to_cart() {
    global $woocommerce;


    remove_action('woocommerce_add_to_cart', __FUNCTION__);

    $product_id = isset($_POST["product_id"]) ? $_POST["product_id"] : $_POST["add-to-cart"];

    if ($unit_ = get_post_meta($product_id,"min_quantity",true)){

        $woocommerce->cart->add_to_cart((int) $product_id ,   ((int) $_POST["quantity"] * $unit_) - 1);

    }


}

Woocommerce Add Code after add to cart form plugin


<?php
add_action( 'woocommerce_after_add_to_cart_form', 'htdat_content_after_addtocart_button' );

function htdat_content_after_addtocart_button() {


    if (get_post_meta(get_the_ID(),"min_quantity",true)){
        echo '<div style="clear: both"></div>
		<div style="margin-top: 10px;color:#0028FF;font-size: 30px">
		 Pack:'.get_post_meta(get_the_ID(),"min_quantity",true).'</div>
		';
    }



}

WooCommerce Order Payment Complete Hook PHP Plugin

Order payment complete hook for woocommerce / wordpress

I always use the hook woocommerce_payment_complete This will fire as the name suggests after the order has been paid.

<?php

function order_payment_complete( $order_id ){
    $order = wc_get_order( $order_id );
    /* Insert your code */
}

add_action( 'woocommerce_payment_complete', 'order_payment_complete' );

PHP woocommerce Limit cart quantity for a product based on category

If you want to set maximum quantities for a products you can use this code in your WordPress/woocommerce plugin.

add_filter( 'woocommerce_add_to_cart_validation', 'limit_cart_items_from_category', 10, 3 );
function limit_cart_items_from_category ( $passed, $product_id, $quantity )
{
    // Accept when cart is empty
    if( WC()->cart->is_empty() ) return $passed;

    // HERE your product categories in this array (can be names, slugs or Ids)
    $categories = array('Biletler');
    $found = $current = false;

    // Check the current product
    if( has_term( $categories, 'product_cat', $product_id ) ){
        $current = true;
    }

    // Loop through cart items checking for product categories
    foreach ( WC()->cart->get_cart() as $cart_item ){
        if( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
            $found = true;
            break; // stop the loop.
        }
    }

    // Current product and a cart item match with defined product categories
    if( $found && $current ){
        $passed = false;
        $cats_str = implode('" and "', $categories );
        wc_add_notice( sprintf( __('Aynı anda sadece 1 etkinlik için bilet satınalabilirsiniz.', 'woocommerce' ), $cats_str ), 'error' );
    }
    return $passed;
}

To improve this article ansver those questions :

Set minimum and maximum quantities in WooCommerce

Only Allow 1 Product in the Cart

PHP Delete Files Larger Than 1 Megabyte (MB)

You can change 1048576 for your files. It represents 1 MB.

With this code you can scan and delete all files in all directories and subdirectories.

<?php

function listFolderFiles($dir){
    $ffs = scandir($dir);

    unset($ffs[array_search('.', $ffs, true)]);
    unset($ffs[array_search('..', $ffs, true)]);

    // prevent empty ordered elements
    if (count($ffs) < 1)
        return;


    foreach($ffs as $ff){

        if (strstr($dir,".git")){
            continue;
        }
        if (filesize($dir.'/'.$ff) > 1048576 ){
            echo $dir.'/'.$ff . "\n";
            unlink($dir.'/'.$ff);
        }

        if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);

    }

}

listFolderFiles('.');

WordPress HTTPS Too Many Redirects Problem

Add this lines to your wp-config.php file


$_SERVER['HTTPS'] = 'on';

define('WP_HOME','https://gokhancelebi.net');
define('WP_SITEURL','https://gokhancelebi.net');

When you go to wp login page, if you redirect too many times that means your SSL settings are wrong. Sometimes that is becaouse of Cloudflare or your hosting provider.

PHP CURL EXAMPLES – HTTP GET, POST, PUT, RAW

You can use those functions to make http get, post, put and raw requests.

function httpPostRequest($url, $requestType, $postData)

    {

        $ch = curl_init();

 

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_COOKIESESSION, true);

        curl_setopt($ch, CURLOPT_POST, 1);

 

        if ($requestType == "RAW") {

            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));

            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        } else if ($requestType == "JSON") {

            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

        } else {

            curl_setopt($ch, CURLOPT_HEADER, 0);

            curl_setopt($ch, CURLOPT_POSTFIELDS,

                http_build_query($postData)

            );

        }

 

 

        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');

        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');

 

        $result = curl_exec($ch);

 

 

        return $result;

 

        curl_close($ch);

    }

 

 

    function httpGetRequest($url){

 

        $ch = curl_init();

 

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_COOKIESESSION, true);

        curl_setopt($ch, CURLOPT_HEADER, 0);

 

        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');

        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');

 

        $result = curl_exec($ch);

 

 

        return $result;

        curl_close($ch);

    }