2016-10-26 9 views
-2

私はPHPで非常に初心者です。しかし、私は本当に学びたい.... 私は質問があります。私はWooCommerce Wordpressサイトで作業しており、このコードで出力しています: 返品$ priceHTML; 私は各出力行の前にaline breakで出力を「デザイン」し、いくつかのテキスト出力デザインを行いたいと思いますが、どこに置くのですか?私はコード内のすべての場所を試したと思います。HTML in PHP - 初心者

完全なコードは次のようになります。

<?php 
/** 
* Electro Child 
* 
* @package electro-child 
*/ 

/** 
* Include all your custom code here 
*/ 
// Modify the returned price to show all of the wholesale prices 



add_filter('woocommerce_get_price_html', 'my_wwpp_show_other_prices', 100, 2 ); 
function my_wwpp_show_other_prices($priceHTML, $product) { 

    // Check the current role 
    if(!current_user_can('commaxx')){return $priceHTML;} 

    // Get required Wholesale Suite plugins object first 
    $wholesale_prices_object = WWPP_Wholesale_Prices::getInstance(); 
    $wholesale_roles_object = WWP_Wholesale_Roles::getInstance(); 

    // Get all wholesale roles 
    $wholesale_roles = $wholesale_roles_object->getAllRegisteredWholesaleRoles(); 

    // Loop through all wholesale roles 
    foreach($wholesale_roles as $k => $wholesale_role){ 

     // Get the inputted wholesale price (on the backend) 
     $saved_wholesale_price = get_post_meta($product->id, $k . '_wholesale_price', true); 

     // If the price exists 
     if($saved_wholesale_price){ 

      // Get the price including tax 
      $price_with_tax = $wholesale_prices_object- >getProductShopPriceWithTaxingApplied($product , $saved_wholesale_price); 

      // Add it to the result 
      $priceHTML .= $wholesale_role['roleName'] . ": " . $price_with_tax . "<br>\n"; 

     } 
    } 

    Return $priceHTML; 
} 
?> 

すべての助けのために非常に感謝!

+5

あなたはPHPを学びたいと思いますが、あなたはWordpress/WooCommerceを使い始めていますか?それは、約ooooh、PHPで死んだすべてのもののあなたの熱意を殺すでしょうか? – CD001

+0

小さなステップで試してみると、初心者にはWordPressが高すぎる – Kumar

+0

関数が呼び出される場所を見つけてその周りのレイアウトを変更する必要があります。関数でそれをしないでください。 –

答えて

0

PHPでは、HTMLの作成、変更、または追加は、通常のテキストのstring concatenationと何も変わりません。

あなたがここにできることがあります:

// Add it to the result 
$priceHTML .= $wholesale_role['roleName'] . ": " . $price_with_tax . "<br>\n"; 

に変更:最後に

// Add it to the result 
$priceHTML .= "<span style='csshere'>" . $wholesale_role['roleName'] . ":</span> " . $price_with_tax . "<br>\n"; 

あるいはまた、

Return $priceHTML; 

Return "<div style='some-css;'>" . $priceHTML . "</div>"; 
のようなものへ

これは、関数、特にフレームワーク内で直接HTMLに干渉するのは良い習慣ではないことに注意してください。あなたがPHPを学んでいるなら、あなたはコメントを考慮するかもしれません。