Skip to content

Instantly share code, notes, and snippets.

@juanlistab
juanlistab / yoast-example-add-on.md
Last active August 23, 2024 17:38
Yoast Example Add-On

Creating a WP All Import Add-On

Introduction

Creating a WP All Import add-on is a simple and rewarding process. By following this guide, you'll learn how to integrate custom fields and define import logic, ensuring everything works seamlessly with WP All Import.

Step 1: Register as a Plugin and Add-On

Let's start by defining your plugin with some essential metadata and setting up a class structure. This step involves creating the plugin header and using a singleton pattern to make sure only one instance of the add-on is loaded.

@juanlistab
juanlistab / prevent_customers_import_from_deleting_other_users.md
Created April 21, 2024 16:16
Prevent Customers Import from deleting shop_manager users

Workaround for preventing the Customers Import to delete other user role accounts

This function will prevent the Customers Import from deleting other user roles such as Shop Manager when run with the "Remove users not present in this import file" option.

function is_post_to_delete_on_meta($is_post_to_delete, $pid, $import)
{
    // Check if the current user has the 'shop_manager' role
 if ( user_can( $pid, 'shop_manager' ) ) {
@juanlistab
juanlistab / import-to-atum-barcode.md
Created April 13, 2024 17:31
Import Data to ATUM Barcode using WP All Import #wpallimport #wpai

How to Import Barcodes to the ATUM Inventory Management for WooCommerce plugin using WP All Import Pro.

This function will import data to the ATUM Inventory Management for WooCommerce, more specifically, to the "Barcode" field using a temporary Custom Field and the 'pmxi_saved_post' hook.

Instructions:

  • Add a New Custom Field in WP All Import and name it "_temp_barcode"(see https://d.pr/i/F75Ze9).
  • Paste the function in the Function Editor.
  • The function will use the data from the temp field and insert it in the 'atum_product_data' table, 'barcode' column, for each imported product.
@juanlistab
juanlistab / import-to-atum-suppliers.md
Created April 13, 2024 17:26
Import Data to ATUM Suppliers using WP All Import #wpallimport #wpai

How to Import Suppliers to the ATUM Inventory Management for WooCommerce plugin using WP All Import Pro.

This function will import data to the ATUM Inventory Management for WooCommerce, more specifically, to the "Supplier" field using a temporary Custom Field and the 'pmxi_saved_post' hook.

Instructions:

  • Add a New Custom Field in WP All Import and name it "_temp_supplier"(see https://d.pr/i/3Z8iGv).
  • That field will store the name of the supplier in the import file, and it'll be used to get that supplier's ID from the database. Keep in mind that this will not create new suppliers, so they need to exist on the site before running the import.
  • Paste the function in the Function Editor.
  • The function will use the ID obtained from the supplier's name, in the 'atum_product_data' table, 'supplier_id' column, for each imported product.
@juanlistab
juanlistab / export-jetengine-relations.md
Last active March 20, 2024 20:14
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".
@juanlistab
juanlistab / import-jetengine-relations.md
Last active March 20, 2024 20:13
Import Data to JetEngine Relations

How to Import JetEngine Relations

This snippet will work for One to One, One to Many and Many to Many relationships:

Instructions:

  • Create a "_temp_child" temporary field to store the values of the relations you want to import (see https://d.pr/i/cIooGf). It will accept multiple values separated with commas, and you can use either the ID or the Title.
  • Edit the snippet using the instructions below and paste it in the Function Editor inside WP All Import.
  • The "jet_rel_default" table is the default table used for relations in JetEngine. If you're using a separate table, you'll need to set that table's name instead.
  • You'll need to specify the relationship ID in 'rel_id’; you can find it here (see https://d.pr/i/eSVZ32).
@juanlistab
juanlistab / use-existing-variations-price-for-variations-without-price.md
Created January 29, 2024 04:51
Use the price of an existing variation when importing variations without price

Use the price of an existing variation when importing variations without price

Instructions:

function my_before_variable_product_import($product_id) {
@juanlistab
juanlistab / create-variants-as-child-xml-elements_2.md
Last active December 12, 2023 03:28
Create variations as child XML elements in WP All Export - With Custom Loop for Attributes

Create variations as child XML elements in WP All Export - With Custom Loop for Attributes

Instructions:

// Loop for variations
@juanlistab
juanlistab / create-variants-as-child-xml-elements.md
Created December 12, 2023 02:40
Create variations as child XML elements in WP All Export

Create variations as child XML elements in WP All Export

Instructions:

function my_output_variants( $parent_id ) {
	$xml = '';
@juanlistab
juanlistab / calculate-totals-based-on-product-price.md
Last active October 31, 2023 00:36
Calculate totals based on product price #wpai #hpos #wpallimport

Calculate order totals based on product price in WP All Import

Instructions:

  • Use this code in your Function Editor and leave the Totals field empty.

Disclaimer:

  • This will work with your import using the current tax rates, it won't work for any past rates.
  • Keep in mind that this is an example function, and you may need to modify it to work on your site.