Skip to content

Instantly share code, notes, and snippets.

@kLOsk
Last active June 4, 2018 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kLOsk/c15ffa6a851e7c9a230c98d47459de06 to your computer and use it in GitHub Desktop.
Save kLOsk/c15ffa6a851e7c9a230c98d47459de06 to your computer and use it in GitHub Desktop.
Copy and synchronice a WooCommerce product programmatically with Polylang from frontend
<?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