Add image into product using image url Bitrix API - wordpress

I am developing a Wordpress plugin, which aims to synchonize the data from Woocommerce to Bitrix CRM using Bitrix Product API. Everything is ok except for only 1 thing, which is I don't know how to add image into the product from a specific image url.
The code I used is below as from Bitrix API documentation:
echo '<PRE>';
print_r(CRest::call(
'crm.product.add',
[
'fields' =>[
'NAME' => 'Jack Trinh is on picture3',
'CURRENCY_ID' => 'USD',
'PRICE' => 4900,
'DETAIL_PICTURE': ['https://stan.vn/wp-content/uploads/2022/03/63806_laptop_acer_gaming_aspire_7_a715_75g_18.jpeg', 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==']
'SORT' => 500
]
])
);
echo '</PRE>';
It works well but image cannot be added. So I just post here if anybody have experience in this, please help me.
Thanks a lot.

Related

Implementing cmb_field_map for cmb2

I'm trying to use the cmb_field_map extension by julykaz for cmb2 in a wordpress plugin to display a google map location.
https://packagist.org/packages/julykaz/cmb_field_map
Have successfully installed it into composer and action hook for cmb2_render_pw_map is registering in the page - but no field (or map) displayed.
cmb2 is installed and working correctly. By the documentation on the page, I should just have to add the appropriate type.
I've got:
$cmb_location->add_field( array(
'name' => 'Google Map Location',
'desc' => 'Drag the marker to set the exact location',
'id' => $prefix . 'map',
'type' => 'pw_map'
) );
In the admin edit page the 'name' field is display but nothing for the googlemap (or even a field).
Not sure what I'm missing here...
Look this -> https://github.com/mustardBees/cmb_field_map Propably you've probably forgotten Google Maps API key.

Woocommerce REST API Update Product Categories

I'm using Wordpress 4.9.5 with Woocommerce 3.3.5. I am using the WooCommerce REST API PHP Client Library to update products on the website when they are changed in a separate product management system. That library is using v2 of the REST API.
Using the following code I am successfully updating the basic product data (title, description, sku, price etc) but I can't get the categories to update from Uncategorized. The categories are also not set when using similar code to create a product if it doesn't already exist on the site.
$client = new WC_API_Client( $domain, $consumerKey, $consumerSecret, $options );
$client->products->update( $id, array(
'sku' => $product->sku,
'title' => $product->title,
'type' => $product->type,
'status' => $product->status,
'regular_price' => $product->regular_price,
'description' => $product->description,
'categories' => array(
array(
'id' => 343
),
array(
'id' => 347
)
)
));
As I say, the other fields update as expected. I have confirmed that categories with IDs 343 and 347 definitely exist so I assume I must have a problem with the syntax. As the other fields update the authentication is definitely working.
I have read the official Woocommerce API documentation and based my code on this tutorial. Based on both of those, I'm not sure what I have done wrong.
Thanks for any help or advice.
I resolved this in the end. It was on oversight on my part.
The client library I was using was connecting to what the Woocommerce documentation calls the 'Legacy v2' version rather than the 'v2' version of the API. Categories, image alt tags, meta data etc are not supported in the legacy versions.
I switched from the using library to connecting directly to the 'v2' version using https://sitename/wp-json/wc/v2/endpoint and all is now well.

Very basic Hello World Wordpress Plugin

What I'm looking to do is create a very basic plugin for Wordpress. I've followed countless tutorials and examples, but haven't found anything close to what I'm looking for.
I'm trying to create something simple where it has a link on the admin nav bar, and just shows some static html on the right side of the page. The public wouldn't see anything at all.
This sounds like a simple task, but so far, has been everything but simple. Any help or pointing in the right direction would be appreciated. :)
Create a folder named helloworld in your plugins folder and add a file called helloworld.php. In your PHP file, use a hook to add the link to the admin menu.
<?php
/*
Plugin Name: Hello World
*/
add_action('admin_bar_menu', 'add_navbar_item', 100);
function add_navbar_item($admin_bar){
$admin_bar->add_menu( array(
'id' => 'my-item',
'title' => 'My Item',
'href' => '#',
'meta' => array(
'title' => __('My Item'),
),
));
}

VIP Wordpress REST API - Auotcreate Post and Page

I want to write a program which will create bulk post and bulk pages through a rest api in VIP Wordpress.
According to VIP Wordpress Developer Documentation, it states that wordpress rest api are supported.
and Wordpress Documentation allows us to create both post and pages via rest api.
I do not have access to a VIP wordpress, but has anyone tried to autocreate posts or pages in wordpress using REST API?
Are there any issues regarding this?
if you want to create post page by Rest API in wordpress you have to get authorization which is basically cookies auth , basic auth and oauth.
in bellow i have done by basic auth
<?php
$headers = array (
// 'Authorization' => 'Basic ' . base64_encode( 'username:password' ),
// );
// $response = wp_remote_request( 'url', array(
// 'method' => 'method',
// 'headers' => $headers
// ));
?>
i hope it will be little help for you mate

Creating pages from Ninja form data

I've created a WordPress page with a Ninja form on it that collects miscellaneous data about a product, including some uploaded images. The page with the form is accessible from the main menu by clicking the "Input" item, so the user doesn't need to access the backend to upload their product data.
I now want to put this data into a custom post type called "Listing." There will eventually be thousands of these data sets and so thousands of "Listing" pages, as people come to the site, click Input in the main menu to get to the page with the Ninja form and fill it out.
Could someone tell me how they would go about now building these listing pages from the data the form has collected?
I'm running Ninja's Front-End Post option which supposedly will create a page from the form data. This plugin has some Post creation settings where you can select the post type to create, but this isn't working for me. I would expect the submitted form data to show up under dashboard | Listings, but there's nothing there after submitting the form.
Has anyone gotten this to work?
Thanks for your help.
I think you can use only Ninja Forms without extensions, and hook directly in 'ninja_forms_after_submission' that fires after submission and allow you to use data submitted and perform actions.
This is a starter codebase to achieve your result, but needs to be customized on your needs and your form structure.
add_action( 'ninja_forms_after_submission', 'create_page_from_ninjaform' );
function create_page_from_ninjaform( $form_data ){
// your fields data
$form_fields = $form_data[ 'fields' ];
// !!! this is an example, it depends form fields in your form
$title = $form_fields[ 1 ][ 'value' ];
$content = $form_fields[ 2 ][ 'value' ];
$sample_meta_field = $form_fields[ 3 ][ 'value' ];
$new_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'listing', // be sure this is the post type name
);
$new_post_id = wp_insert_post( $new_post );
update_post_meta( $new_post_id, 'your_meta_key', $sample_meta_field );
}
This code should be copied in functions.php file
Not tested of course.
Good luck ;)
The Ninja Forms Front-end Posting extension isn't really meant for displaying form submission data on the front end.
From: https://ninjaforms.com/extensions/front-end-posting/
"The Ninja Forms Front-end Posting extension gives you the power of the WordPress post editor on any publicly viewable page you choose."
If you want to show Ninja Forms submission data on the front end, you will have to retrieve them from the database with code in functions.php or by writing a plugin (recommended). You could then parse and manipulate them and create a shortcode that would allow you to insert your formatted submission data easily in Wordpress posts or pages.
Here's a link to a feature request, asking for the same thing. The author of that request posted a link to a plugin (click Download as Plugin) they wrote which may do what you want or give you further insights as to how you could implement this.
https://github.com/wpninjas/ninja-forms/issues/892
If you do not mind paying a little money for a plugin I would recommend using gravity forms rather then ninja forms for more advanced stuff like this.
I manually create a custom post type "oproep" and used a gravityforms plugin to create a custom post from type oproep when an user submits the form.
Because you use custom post type archive pages www.mysite.com/oproep will be automatically created so you already have a list of "Listings". The singe pages www.mysite.com/oproep/title will also be created for you by default, you could override these templates as well if you would like depending on your theme.
The only thing you have to do is add a few php lines to your functions.php (or write your own plugin) that adds the custom post type. The rest all works automatically.
I went so far as writing code to make users able to edit their submissions, read custom taxonomy tags in dropdowns etc. You got lots and lots of more options using gravity forms.
FrancescoCarlucci's answer is correct, but just adding an additional comment: in case you want to specify by form field IDs which fields should go where in your post, NinjaForms passes the ID as a number (in my case for example, I needed field 136 for my post title). It may have been obvious but I racked my brain for a while until I figured it out.
function create_post($form_data) {
$form_fields = $form_data[ 'fields' ];
$post_fields = array(
'post_content' => '',
'post_content_filtered' => '',
'post_title' => '',
'post_excerpt' => '',
'post_status' => 'pending',
'post_type' => 'post',
);
foreach ($form_fields as $field) {
$field_id = $field[ 'id' ];
$field_key = $field[ 'key' ];
$field_value = $field[ 'value' ];
if ($field_id == 136) {
$post_fields['post_title'] = $field_value;
}
}
wp_insert_post($post_fields, true);
}

Resources