Skip to content

Commit

Permalink
Merge branch '6.3.0.wpml' into 6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
codersaiful committed May 20, 2024
2 parents 2d2ca85 + 8c5f3e0 commit 1a59119
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
3 changes: 2 additions & 1 deletion admin/page/main-page/supported-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
return empty(strpos($parenttt, 'attributes'));
});
$supported_terms = isset( $saved_data['supported_terms'] ) ?$saved_data['supported_terms'] : array( 'product_cat' );
$ourTermList = $select_option = false;
$select_option = false;
$ourTermList = [];
if( is_array( $term_lists ) && count( $term_lists ) > 0 ){
foreach( $term_lists as $trm_key => $trm_object ){
// var_dump($trm_object->labels->back_to_items);
Expand Down
54 changes: 50 additions & 4 deletions includes/min-max-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class Min_Max_Controller extends Base
protected $product;
protected $variation_product;

//Special for WPML
protected $wpml_lang;
protected $wpml_default_lang;
protected $wpml_bool;

/**
* New added for make instance
*
Expand All @@ -106,6 +111,11 @@ public function __construct()
$this->options = WC_MMQ::getOptions();
$this->term_data = $this->options['terms'] ?? null;

//Special for WPML
$this->wpml_lang = apply_filters( 'wpml_current_language', NULL );
$this->wpml_default_lang = apply_filters('wpml_default_language', NULL );
$this->wpml_bool = $this->wpml_lang == $this->wpml_default_lang ? false : true;

if( ! empty( $this->term_data ) ){
$this->term_data = wcmmq_tems_based_wpml( $this->term_data );
}
Expand Down Expand Up @@ -255,6 +265,7 @@ public function single_variation_handle()
{
if( ! defined('WC_MMQ_PRO_VERSION') ) return;
global $product;
$product = $this->purefy_product( $product );
$this->product_id = $product->get_id();
$this->product = wc_get_product( $this->product_id );
$variables = $product->get_children();
Expand Down Expand Up @@ -632,6 +643,10 @@ public function set_input_args( $args, $product )
// dd($args);
if( $product->is_sold_individually() ) return $args;
$this->product = $product;
if( $this->wpml_bool ){
$default_product_id = apply_filters('wpml_object_id', $this->product->get_id(), 'product', false, $this->wpml_default_lang);
$this->product = wc_get_product( $default_product_id );
}
$this->variation_id = null;
$this->product_id = $this->product->get_id();
$this->get_product_type = $this->product->get_type();
Expand Down Expand Up @@ -749,6 +764,25 @@ public function compatible_with_other_plugins($args)
return $args;
}

/**
* Specially made for WPML
* But we can use it for defferent perpose.
*
* Returns the default product if WPML is enabled, otherwise returns the original product.
*
* @param mixed $product The original product object.
* @return mixed The default product object if WPML is enabled, otherwise the original product object.
*/
public function purefy_product( $product )
{
if( $this->wpml_bool ){
$default_product_id = apply_filters('wpml_object_id', $product->get_id(), 'product', false, $this->wpml_default_lang);
return wc_get_product( $default_product_id );
}
return $product;
}


/**
* Individule quantity setup using single filter
*
Expand All @@ -761,7 +795,8 @@ public function quantity_input_step($qty, $product)
if( ! is_object( $product ) ) return $qty;
if( ! method_exists($product, 'is_sold_individually') ) return $qty;
if( $product->is_sold_individually() ) return $qty;
$this->product = $product;
$this->product = $this->purefy_product( $product );

$this->product_id = $this->product->get_id();

//Need to set organize args and need to finalize
Expand All @@ -782,7 +817,7 @@ public function quantity_input_min($qty, $product)
if( ! is_object( $product ) ) return $qty;
if( ! method_exists($product, 'is_sold_individually') ) return $qty;
if( $product->is_sold_individually() ) return $qty;
$this->product = $product;
$this->product = $this->purefy_product( $product );
$this->product_id = $this->product->get_id();

//Need to set organize args and need to finalize
Expand All @@ -801,7 +836,7 @@ public function quantity_input_min($qty, $product)
public function quantity_input_max($qty, $product)
{
if( $product->is_sold_individually() ) return $qty;
$this->product = $product;
$this->product = $this->purefy_product( $product );
$this->product_id = $this->product->get_id();

//Need to set organize args and need to finalize
Expand All @@ -811,7 +846,7 @@ public function quantity_input_max($qty, $product)
}
public function api_quantity_input_max($qty, $product)
{

$product = $this->purefy_product( $product );
$final_qty = $this->quantity_input_max($qty, $product);
if( empty($final_qty) || ! is_numeric( $final_qty ) ) return PHP_INT_MAX;

Expand Down Expand Up @@ -1069,14 +1104,25 @@ class="wcmmq-json-options-data"
*/
private function getMeta($meta_key)
{
if($this->wpml_bool){
$this->product_id = apply_filters('wpml_object_id', $this->product_id, 'product', false, $this->wpml_default_lang);
$this->product = wc_get_product( $this->product_id );
}

$value = get_post_meta($this->product_id,$meta_key,true);
if( is_numeric( $value ) ) return $value;
return '';
}

private function getMetaVariation($meta_key)
{
if($this->wpml_bool){
$this->variation_id = apply_filters('wpml_object_id', $this->variation_id, 'product', false, $this->wpml_default_lang);

}

$value = get_post_meta($this->variation_id,$meta_key,true);

if( is_numeric( $value ) ) return $value;
return '';
}
Expand Down

0 comments on commit 1a59119

Please sign in to comment.