Skip to main content

Posts

Showing posts with the label Web Development

WooCommerce: Adding a LEFT JOIN to after woocommerce_get_catalog_ordering_args

I'm trying to order my posts by the nearest location to a user. To solve this issue I created a table called geolocation that contains all latitude(lat) and longditude(long) of by post_id. In order to sort the posts I used the following hook: woocommerce_get_catalog_ordering_args The issue I'm facing Is that I need to join the table I created so I can order the products by lat and long ( ORDER BY (POW((geodata.long-9.9533548),2) + POW((geodata.lat-49.7913044),2)) ASC ) Using various examples this is what I've came up with - however I'm receiving a 500 Internal error and I'm unsure how to get the join working so I can order by attributes in another table: add_filter( 'woocommerce_catalog_orderby', 'add_custom_sorting', 99999); function add_custom_sorting( $options) { $options['distance'] = 'Nach Standort sortieren'; return $options; } add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_sorting_f

loggedin user bought product. the "add to cart"button text change to"view now"and view now button link changed that will open order detail in endpoint [closed]

problem - currently add to cart button not showing button"view order now" after order status complete in product page also in the shop archive page, so that user can download the product file by clicking on "view order now" button. which will direct to account endpoint view order detail. below is steps needed to solve - code check the logged-in user bought product. the add to cart button text changed to "view order now" this "view order now" button and also button link changed that will open view order detail in order section in my account of the logged-in user (of bought product)so that user able to download the file there and don't worry by finding in the list of orders in my account section. and also I tried to add step 4.- I need an option to add a custom link set by me not a customer of a specific product to send them in custom URL. here is the image that I want to achieve. image and here is below the incomplete code I

Symfony ssl parameters setup in doctrine connection [duplicate]

I'm trying to connect Mysql with SSL connection in symfony 3.4. I have tested plain PDO connection and it works fine but when I tried to integrate to same in Symfony, I get errors. Plain PDO connection which works fine $pdo = new PDO('mysql:host=HOST', 'USER', 'PASS', array( PDO::MYSQL_ATTR_SSL_CA =>'certificate.crt.pem', )); Following is the list of options i have tried in symfony but failed Method 1 #app/config/config.yml dbal: < other config> options: !php/const:PDO::MYSQL_ATTR_SSL_CA: %ca_cert% Method 2 #app/config/config.yml dbal: < other config> options: MYSQL_ATTR_SSL_CA: %ca_cert% Method 3 #app/config/config.yml imports: - { resource: parameters.php } dbal: < other config> options: %pdo_options% #parameters.php $this->container->setParameter("pdo_options", [ PDO::MYSQL_ATTR_SSL_CA => "certicate.crt.pem", ]); I'm seeing this error for all the

Submit form with AJAX and PHP without page reload

I have "add to favorite" feature in my wordpress project, I am using <form> to submit the feature. Each time I click on add to fav button it works, but the page is always reloaded which is annoying so I decided to use AJAX, but I can not connect it with my PHP file. This is PHP file, where I wrote function for the feature if (! function_exists('favorite_button_icon')) { function favorite_button_icon() { echo apply_filters( 'favorite_button_icon', get_the_favorite_button_icon() ); } } if (! function_exists('get_the_favorite_button_icon')) { function get_the_favorite_button_icon() { $output = ''; $action = $currentPath; // window.location.href $name = is_favorite() ? 'remove_favorite' : 'add_favorite'; $class = 'favorite-button-pro' . ( is_favorite() ? ' favorite' : '' ); $icon = is_favorite() ? 'Added' : 'Add';

Configuring Remote (WSL) Composer in PHPStorm

I'm trying to configure a PHPStorm project to utilize both remote PHP and a remote Composer. Remote being my Windows Subsystem for Linux (WSL) installation. However, when I initiate any Composer commands from PHPStorm, I get errors. And unfortunately, the errors are not very indicative of the cause or offer a link for additional details. Errors received in my "Event Log": 12:21 PM Composer Failed to install packages for ./composer.json. Show in Log And in my "Composer Log": install --no-interaction --no-ansi /bin/sh: 1: composer: not found Failed to install packages for ./composer.json. So far, I've followed the instructions located at: https://www.jetbrains.com/help/phpstorm/how-to-use-wsl-development-environment-in-product.html https://www.jetbrains.com/help/phpstorm/configuring-remote-interpreters.html I also followed the answer at this post to set WSL as my default terminal: How to use WSL as default terminal in WebStorm or any other JetBra

Preview Displaying Different than Live Site wordpress

I've issue with wordpress project, the Preview Displaying page Different than the same page in Live Site, the differences like that: in the Preview Displaying and editing mode: the same page in Live Site: the images in the live site doesn't show, However, its "src" appears in the inspect! could you help me source https://stackoverflow.com/questions/70641131/preview-displaying-different-than-live-site-wordpress

Is it possible to reload a parent php file WITHOUT javascript?[WORKS !]

Is it possible to reload a parent php file WITHOUT javascript ?I dont wanna use Javascript because if the client has disabled Javascript . So I have a object and there should be a button to change the background color of the main page parent.php : <!doctype html> <html> <head> <title>This is the title of the webpage!</title> <?php session_start(); $_SESSION['backgroundcolor'] = '#fcba03'; ?> </head> <body style="background-color:<?php echo $_SESSION['backgroundcolor'];?>"> <object data="changebackground.php" width="500" height="200"> </object> </body> </html> changebackground.php : <form action="" method="post"> <input type="submit" value="change bgcolor" name="submit"> </form> <?php $var = "#ff0000"; if (isset($_POST

Custom Wordpress Nav with wp_nav_menu function

I am struggling to get the wp_nav_menu function working with my custom html. I have tried looping over the items but had no success hence why I went back to the native function. I have attached the order of the menu items in wordpress and the HTML I am trying to loop over with the values I am tying to insert in them. The duplicate pages are just so other menu sections have pages. Menu Order in WP What We Do(parent) Sectors(child of parent) Audit(child of child) Component Solutions Blog Single Case Studies Products Resources Component Case Studies Blog Single Blog About Component Case Studies Blog Single Case Studies HTML for looping over <!-- Should loop per parent --> <div class="header-dropdown w-dropdown> <div class="header-dropdown-toggle w-dropdown-toggle"> <div class="dropdown-text">{parent.title}</div> </div>

Restrict the amount of categories in mega menu and reorder it

I have a necessity to dig into my WP template and apply some changes. I've bought it by GPL license, so kind of unable to get direct support from the author, so here is the question: What I've got now: mega menu with which output all existing child categories originally sorted by name. What's needs to be done: mega menu which output specific amount of child categories sorted by the number of posts . I successfully solved the problem with the amount of categories here: public function build_subcat_menu( $category ) { $subcat_output = $subcat_li = ''; $children = get_categories( [ 'parent' => $category ] ); if ( ! empty( $children ) ) { foreach ( $children as $child ) { $subcat_li .= "<li data-cat-id=\"{$child->term_id}\" class=\"\"><a href=\"" . get_category_link( $child->term_id ) . "\">{$child->name}</a></li>";

SQL conversion from week date format [closed]

I am trying to figure out how to convert from a weekly date format like 2021-W45 being used as the 45th week of 2021. I have MySQL and PHP available for this conversion and have had no luck thus far. Ideally I'd like to convert this to YYYY-MM-DD format but really I just trying to figure out any way to get it out of the YYYY-W# format. Appreciate any tips! source https://stackoverflow.com/questions/70643758/sql-conversion-from-week-date-format

How to uncomment extension=php_pdo_mysql.dll in Cpanel Web Hosting in PHP.ini

I am Trying to Publish Online a Website Developed with PHP PDO, So After I uploaded the All Files to The Online Server, but I am Got This Error Connection failed: could not find driver. <?php // Config Credentioals \ $server = 'host'; $user = 'user'; $password = 'password'; $databse = 'db_name'; try { $dns = "mysql:host=".$server.";dbname=".$databse; $config = new PDO($dns, $user, $password); // set the PDO error mode to exception $config->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }catch(PDOException $e) { die("Connection failed : " . $e->getMessage()); } ?> source https://stackoverflow.com/questions/70643716/how-to-uncomment-extension-php-pdo-mysql-dll-in-cpanel-web-hosting-in-php-ini

Session is not continuing [closed]

So I am making a login and a profile page using NextJS and a PHP-api. Everything is working fine in backend, meaning trying to login and get userdata from profile is working as i should when using Postman. I then get all userdata as I should from current session. It is however not working when trying to fetch the session using Axios from NextJS. Does anyone know why I then can't fetch the session? Is it because it is two different calls? This is the error I am getting in console ( even tough I have session_start() on line 1 ): Warning : Undefined array key "valid" in C:\xampp\htdocs\nettsider\next_js\drikke-4real\pages\api\getManufacturerData.php on line 11 source https://stackoverflow.com/questions/70643685/session-is-not-continuing

PHP 8.1 throws error Uncaught TypeError: Cannot access offset of type string on string

I am checking all my code in readiness for upgrading to PHP 8.1. The following lines of code work fine in PHP7.4 but throws the above error on the line starting with "$pcount" in PHP 8.1 foreach ($products as $product) { $pcount[$product['HospitalProductID']] += 1; } The $product array looks like this: ( [HospitalProductID] => 260 [HospitalProtocolID] => 82 ) Any idea why PHP 8.1 does not like this code? source https://stackoverflow.com/questions/70628519/php-8-1-throws-error-uncaught-typeerror-cannot-access-offset-of-type-string-on

Unable to restrict unique random generation to required output

I want to restrict the unique numbers to be only 8 characters long with my prefix. Here is what i do $prefix = "CEVO"; $u_unique_id = str_shuffle(md5(uniqid(rand(100000,999999), true))); $user_unique_id = $prefix.$u_unique_id; But this code isn't restricting to 8 characters. Where i am wrong? source https://stackoverflow.com/questions/70635786/unable-to-restrict-unique-random-generation-to-required-output

CRUD, Undefined array key PHP [duplicate]

Hey i have a problem in my code i dont understand why i have searched everywhere with no results. I added well enctype="multipart/form-data" in the form, My error is : Warning: Undefined array key "fichier" in F:\3_Application_XAMPP\htdocs\PR_DATA\V2\backend\save.php on line 9 Warning: Trying to access array offset on value of type null in F:\3_Application_XAMPP\htdocs\PR_DATA\V2\backend\save.php on line 9 Warning: Undefined array key "fichier" in F:\3_Application_XAMPP\htdocs\PR_DATA\V2\backend\save.php on line 11 Warning: Trying to access array offset on value of type null in F:\3_Application_XAMPP\htdocs\PR_DATA\V2\backend\save.php on line 11 Database info save.php : <?php include 'database.php'; if(count($_POST)>0){ if($_POST['type']==1){ $mandataire=$_POST['mandataire']; $entreprise=$_POST['entreprise']; $description=$_POST['description']; $nomfichi

How to get value from array with objects?

I try to use api.openweathermap.org for get current weather. I use a php request to get a data. I sucessfully receive data and convert it to array with objects. I have a small question: How to get a value of key named "MAIN", which is equal to "Snow"? I try to use api.openweathermap.org for get current weather. I use a php request to get a data. I sucessfully receive data and convert it to array with objects. I have a small question: How to get a value of key named "MAIN", which is equal to "Snow"? object(stdClass)#3 (14) { ["coord"]=> object(stdClass)#1 (2) { ["lon"]=> float(30.2642) ["lat"]=> float(59.8944) } ["weather"]=> array(1) { [0]=> object(stdClass)#4 (4) { ["id"]=> int(600) ["main"]=> string(4) "Snow" ["description"]=> string(27) "small snow" ["

Multiple where conditions with several different cases

I have an issue I just cant get my head around, like logically. Here is the situation: I have an user who an submit an application, said application can either be: Canceled by the user canceled by the company accepted by the company Now to avoid someone submitting an application for a job multiple times I need to check if either of those values are true, here is my migration for an application: public function up() { Schema::create('bewerbungens', function (Blueprint $table) { $table->id('Bewerbung_ID'); $table->string('bewerber_email'); $table->bigInteger('Stellenanzeigen_ID'); $table->boolean('is_Accepted')->default(false); $table->date('accept_Date')->nullable(); $table->boolean('is_Canceled')->default(false); $table->date('cancel_Date')->nullable(); $table->boole

WordPress plugin function didn't delete the post meta

I have plugin function where I want to delete specific postmeta if they're exists in every posts based on condition (which is fulfilled with my testing post) but it didn't delete the metadata.. The code: add_action('init', 'survey_start_type_validation'); function survey_start_type_validation($post_id) { $type_of_running = get_post_meta($post_id, 'spusteni_dotazovani'); if($type_of_running == 'manually_run') { if(metadata_exists('survey', $post_id, 'datum_a_cas_planovaneho_spusteni') == true) { delete_post_meta($post_id, 'datum_a_cas_planovaneho_spusteni'); delete_post_meta($post_id, '_datum_a_cas_planovaneho_spusteni'); } } elseif($type_of_running == 'planned_run') { if(metadata_exists('survey', $post_id, 'running_status') == true) { delete_post_meta($post_id, 'running_status'); delete_post_meta($p

How can I send whatsapp message to multiple numbers by using ultramsg and PHP

I am trying to send WhatsApp message to multiple numbers by using Ultramsg.com using PHP by reference: https://docs.ultramsg.com/api/post/messages/chat the code is like this: <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.ultramsg.com/instance1xxx/messages/chat", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "token=exxxxxxxx&to=1408XXXXXX1 @c.us,1408XXXXXX2 @c.us&body=WhatsApp API on UltraMsg.com works good&priority=10", CURLOPT_HTTPHEADER => array( "content-type: application/x-www-form-urlencoded" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } but