Skip to content

Instantly share code, notes, and snippets.

View trey8611's full-sized avatar
💭
listening to n*sync

Trey trey8611

💭
listening to n*sync
View GitHub Profile
@trey8611
trey8611 / import-woodmart-additional-variation-images.md
Last active May 3, 2024 17:45
[WoodMart Additional Variation Images]
function wpai_woodmart_gallery_image_imported( $post_id, $att_id, $filepath, $is_keep_existing_images = '' ) {
	$product = wc_get_product( $post_id );
	if ( ! $product ) return;

	$variationID_first = get_post_meta( $product->get_id(), wpai_woocommerce_add_on\XmlImportWooCommerceService::FIRST_VARIATION, TRUE );
	if ( $product->is_type( 'variation' ) || ! empty( $variationID_first ) ) {
		if ( empty( $variationID_first ) ) {
			$variationID = $product->get_id();
			$parent      = $product->get_parent_id();
@trey8611
trey8611 / import-optimizations.md
Last active April 17, 2024 17:40
WP All Import - Optimize your import speed.
@trey8611
trey8611 / wpai-check-if-image-exists.md
Created December 3, 2020 20:51
WP All Import | Check if images exist/are downloadable before trying to download them.

If you provide an image URL that's invalid or that's not available to the server, it can take a while for WP All Import to fail when attempting to download it. To get around this, you can pass your images to a function (see https://www.wpallimport.com/documentation/developers/custom-code/inline-php/) like this:

[my_output_imgs(array({img1[1]},{img2[1]},{img3[1]}))]

Then, use PHP to test them before outputting them in the import template:

@trey8611
trey8611 / custom-log-functions.md
Created November 19, 2021 16:28
[WP All Import] Custom log / custom logging functions with our API

This shows how to save a custom log of imported items. It can be adjusted to include any product data.

  /***********************************************/
 /***** BEGIN LOG CREATE / UPDATE / DELETE  *****/
/********************************************* */

// This creates a custom log file in the root WordPress uploads folder
// Some of this code will need to be adjusted, please read comments.
@trey8611
trey8611 / find-woocommerce-attributes-by-name.md
Last active April 17, 2024 17:24
[Find WooCommerce Attributes by Name] Search by name instead of slug only. #wpallimport #woocommerce

Find attributes by name.

function my_find_attribute_by_name( $name, $attribute ) {
    global $wpdb;
    $term_table = $wpdb->prefix . 'terms';
    $taxonomy_table = $wpdb->prefix . 'term_taxonomy';

    if ( ! empty( $name ) ) {
@trey8611
trey8611 / remove-image-sizes-from-url.md
Last active April 17, 2024 17:24
Remove image sizes from image URLs in content

Remove -000x000.ext from image URLs in content by passing the content to a custom PHP function:

[my_fix_images({content[1]})]

Code (save in the Function Editor at All Import › Settings):

function my_fix_img( $img = '' ) {
@trey8611
trey8611 / query_cyrillic_attribute_values.md
Last active April 17, 2024 17:23
WP All Import - use XPath Query based on Cyrillic attribute value

XPath doesn't allow you to make queries with Cyrillic symbols unless you disable XML pre-processing by adding this code in your child themes functions.php file (or in a plugin like Code Snippets: https://wordpress.org/plugins/code-snippets/):

function wpai_is_xml_preprocess_enabled( $is_enabled ) {
	return false;
}
add_filter( 'is_xml_preprocess_enabled', 'wpai_is_xml_preprocess_enabled', 10, 1 );

Once that code is in place, upload your file to an import and queries like this will be possible:

@trey8611
trey8611 / adjust-wooco-variation-threshold.md
Last active April 9, 2024 11:53
Adjust WooCommerce Variation Threshold

By default, WooCommerce only loads 30 variations on the front-end for variable products. If your product has more variations than that, WooCommerce will not fetch them until they're selected in the drop-downs - which means that unavailable variations will show up in the drop-downs.

If you don't want WooCommerce to display unavailable options in the drop-downs, you'll have to adjust the WooCommerce AJAX Variations Threshold to be more than the amount of variations your product has.

Here's an example snippet that tells WooCommerce to load 100 variations:

function soflyy_change_threshold( $amount, $product ) {
 return 100; // change this to the amount of variations you want to load
@trey8611
trey8611 / migrate-shortcode-image-ids.md
Last active April 3, 2024 03:18
How to migrate shortcode image IDs | Visual Composer / WPBakery / ETC

Migrate shortcode image IDs with WP All Export and WP All Import

Convert the IDs to URLs during the export

Use a custom PHP function ( https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/ ) on the content field to convert the image IDs to URLs. Example shortcode:

[vc_single_image image="177" img_size="full" add_caption="yes" alignment="center" style="vc_box_shadow_border"]

Example function:

@trey8611
trey8611 / export-jetengine-relations.md
Created March 20, 2024 20:14 — forked from juanlistab/export-jetengine-relations.md
Export JetEngine Relations with WP All Import

How to Export JetEngine Relations

This function will use the default "jet_rel_default" table in JetEngine to look for the post_id of the parent and return its relations from the "child_object_id" column. If you're using a separate table for your relations, you can change the $table_name value.

Instructions:

  • Add a New Field in WP All Export (see https://d.pr/i/OW9dze).
  • Set a name for the column and use "ID" for the field to export (see https://d.pr/i/v5Mq98).
  • Modify the function as needed, paste it in the Function Editor and paste the name of the function in the "Export the value returned by a PHP function" field (see https://d.pr/i/2c6c07).
  • The function will return a list of IDs separated with pipes by default, but if you want to export the titles instead, you need to change the $mode in "function my_export_je_relation ($post_id, $mode = 'id')" to "title".