Last active
June 4, 2018 21:29
-
-
Save kLOsk/c15ffa6a851e7c9a230c98d47459de06 to your computer and use it in GitHub Desktop.
Copy and synchronice a WooCommerce product programmatically with Polylang from frontend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* I had a hard time accessing the Polylang PLL_Admin methods from the frontend. Instantiating classes manually didnt work. | |
* Luckily the Polylang boss jumped in and provided this solution. This shold also be working with other Polylang methods | |
* that can normally only be executed from admin side. | |
*/ | |
$pll = new PLL_Admin( PLL()->links_model ); | |
$pll->add_filters(); | |
$pll_pro = new Polylang_Pro(); | |
$pll_pro->load_modules( $pll ); | |
$pll->sync_post->copy_post( $post_id, $lang, true); | |
/* Description of the copy_post method | |
/** | |
* Duplicates the post to one language and optionally saves the synchronization group | |
* | |
* @since 2.2 | |
* | |
* @param int $post_id Post id of the source post | |
* @param string $lang Target language | |
* @param bool $save_group True to update the synchronization group, false otherwise | |
* @return int Post id of the target post | |
*/ | |
public function copy_post( $post_id, $lang, $save_group = true ) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment